使用canvas元素作为图像缓冲区更有利还是使用img元素作为缓冲区更有利?
我想在画布上用图像制作大量动画;使用canvas元素作为图像缓冲区更有利(这样我们就不必再次调整大小),还是使用img元素作为缓冲区更有利?
或者实际上是否有更好的方法,如果性能是我应该做的首要任务而我却错过了,那么这是必须做的?
另外,为什么“清除”画布的操作如此缓慢?我的背景是 Windows Phone 7 的 xna 编程,“清除”整个屏幕是最快的操作之一。
另外,我应该通过设置 width=width 来“清除”画布,还是应该执行 drawRect(0,0,width,height) ?
I want to do a ton of animation with images on canvas; is it more beneficial to use a canvas element as a buffer for the image (so that we do not have to resize again) or is it more beneficial to use an img element as a buffer?
Or is there actually a better way, a must-do if performance is top-priority that I should do and I'm missing?
Also, why is "clearing" the canvas such a slow operation? My background is xna programming for windows phone 7 and "clearing" the whole screen is one of the fastest operation.
Also, should I "clear" the canvas by setting width=width or should I do a drawRect(0,0,width,height) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用画布元素作为转换图像的缓冲区,并在整数坐标上对齐您的drawImage调用。一旦需要转换图像,软件画布实现就会变慢(因为转换 = 重新采样 = 慢。)
请参阅:http:// jsperf.com/canvas-drawimage
清除画布,使用clearRect: http://jsperf.com /canvas-clear-speed
You should use canvas elements as buffers for transformed images and align your drawImage calls on integer coords. Software canvas implementations get slow once you need to transform the image (because transforming = resampling = slow.)
See: http://jsperf.com/canvas-drawimage
Clearing the canvas, use clearRect: http://jsperf.com/canvas-clear-speed