HTML5 - Canvas - Optimization for large images

不羁岁月 提交于 2019-12-10 19:22:03

问题


I need to build a HTML5 canvas which contains an very large image, maybe up to 10-15MB. My first idea was to split the image into several chunks which will be loaded when moving horizontally through the canvas.

Any thoughts about this idea? Is it a good one? Maybe I'm missing some optimization feature already implemented?


回答1:


You're spot on, and such tiling is how most apps that serve large images (like google maps) work.

Unfortunately, there aren't any other clever optimizations to be had here.




回答2:


It may be a good idea, but it depends on your application. The time required to download the image can be believed to be small, and often is, but it's truly unpredictable. So depending on your application being a static one (Google maps) or a dynamic one (a game), lazy loading may or may not be a good idea.

If the use can wait, you can safely split your images in different tiles and loading them on demand.

If it's a game, you'd better preload everything before it even starts - at least preloading a single level, but I don't know if it contains levels, we haven't even been told if it's a game :)




回答3:


If it's not something that needs to respond instantly, What you might do too, is use a server script to pull up whatever piece of the larger image you need, so instead of relying on pre-sized tiles, you could create an image, set it's source to

'imageSliceScript.php?x=whatever&y=whatever'

then draw that to the canvas, or just leave it as an image. That way you're only getting the piece of the image you need at that moment, and never have to deal with an issue like you viewport being across multiple tiles at the edges.



来源:https://stackoverflow.com/questions/12579478/html5-canvas-optimization-for-large-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!