The invention discloses a large capacity image caching method based on WebGL, which comprises the following steps: converting a large number of image objects through the canvas object will need to cache for WebGL texture objects, and WebGL cache to context; when the image object to get a lot of like one, using the WebGL shader program one texture object corresponding to the object, displayed on the canvas image cache object; this method is applicable to support the WebGL standard browser. Since the total area of the WebGL cache image is very large, it is generally possible to cache several G sized images on PC browsers, several to several times the maximum number of images supported by browsers. In the same operating environment, the cached image is fast, and the time it takes for the WebGL render to get the target can be completed within 1 milliseconds. Compatibility is good. All browsers that support WebGL support and are compatible with all types of images, and the resolution of the image is not affected.
【技术实现步骤摘要】
基于WebGL的大容量图像缓存方法
本专利技术属于图像显示领域,涉及一种基于WebGL的大容量图像缓存方法。
技术介绍
传统做法一般直接使用Image对象直接缓存图片。如下图像加载代码所示:图像加载(JS)varimage=newImage();image.src=“http://XXX.xx/image.image”;但是每个浏览器能容纳的Image的对象的总大小是有限的,特别是移动设备的浏览器,一般浏览器限制内存里的image对象的总面积大小不能大于10000*10000(100M,估计值)大小。这个容量还是比较小的。当需要在浏览器中查看大量网页时,由于浏览器的容量较小,导致大量图像缓存很慢,严重影响浏览器端大量图像的获取和查看速率。
技术实现思路
本专利技术的一个目的是解决至少上述问题和/或缺陷,并提供至少后面将说明的优点。本专利技术还有一个目的是提供一种基于WebGL的大容量图像缓存方法。为此,本专利技术提供的技术方案为:一种基于WebGL的大容量图像缓存方法,包括如下步骤:通过canvas对象将需要缓存的大量image对象转换为WebGL的texture对象,并缓存至WebGLcontext中;当要获取所述大量image对象的其中一个对象时,利用WebGL的shader程序将该其中一对象对应的texture对象通过canvas对象展示出来;该方法适用于支持WebGL标准的浏览器的图像缓存。优选的是,所述的基于WebGL的大容量图像缓存方法中,所述通过canvas对象将需要缓存的大量image对象转换为WebGL的texture对象,并缓存至WebGL ...
【技术保护点】
一种基于WebGL的大容量图像缓存方法,其特征在于,包括如下步骤:通过canvas对象将需要缓存的大量image对象转换为WebGL的texture对象,并缓存至WebGL context中;当要获取所述大量image对象的其中一个对象时,利用WebGL的shader程序将该其中一对象对应的texture对象通过canvas对象展示出来;该方法适用于支持WebGL标准的浏览器的图像缓存。
【技术特征摘要】
1.一种基于WebGL的大容量图像缓存方法,其特征在于,包括如下步骤:通过canvas对象将需要缓存的大量image对象转换为WebGL的texture对象,并缓存至WebGLcontext中;当要获取所述大量image对象的其中一个对象时,利用WebGL的shader程序将该其中一对象对应的texture对象通过canvas对象展示出来;该方法适用于支持WebGL标准的浏览器的图像缓存。2.如权利要求1所述的基于WebGL的大容量图像缓存方法,其特征在于,所述通过canvas对象将需要缓存的大量image对象转换为WebGL的texture对象,并缓存至WebGLcontext中的具体方法包括如下步骤:1.1)构建一个canvas对象,并从其取得WebGLcontext;1.2)从WebGLcontext中取出当前设备支持的texture个数的最大值和texture大小的最大值;1.3)根据texture大小的最大值生成Canvas对象大小的最大值,并将需要缓存的图像使用canvas的drawimage方法按顺序绘制到指定的区域,当该canvas绘制满后,将该canvas转换成WebGL的texture对象,并缓存至WebGLcontext中;1.4)依次循环重复2)和3),直至所有image对象缓存完或者创建的texture对象数目达到了所述texture个数的最大值。3.如...
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。