是putImageData比drawImage快吗? [英] Is putImageData faster than drawImage?

查看:150
本文介绍了是putImageData比drawImage快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为putImageData比drawImage快,但是我需要证明这一点。

I think putImageData is faster than drawImage, but I need to prove it.

我想与Flash及其Bitmap和BitmapData类的情况相同。基本上,BitmapData有助于以非可视方式提取Bitmap对象中的数据,从而可以非常轻松,快速地对其进行操作。

I guess it is the same case as with Flash and its Bitmap and BitmapData classes. Basically, BitmapData facilitates a non-visual extraction of the data in a Bitmap object, which allows for very easy and fast manipulation of it.

我猜想诸如游戏之类的性能案例,比一遍又一遍地将精灵本身绘制到画布上,是一种更好的解决方案,例如游戏,从每个图像(例如,每个精灵)提取ImageData并将其缓存在资产字典中。

I'm guessing that in high-performance cases, such as games, extracting the ImageData from every image (for instance, every sprite) and caching it in an "assets" dictionary is a better solution than drawing the sprites themselves onto the canvas over and over again.

有人可以证明这一点吗?

Could someone prove this?

推荐答案

我对此测试不以为然一起使用,但是您可以清楚地看到将 drawImage()与画布和图像一起使用的性能,以及 putImageData()此处:

I take no credit for putting this test together, but you can clearly see the performance of using drawImage() with both a canvas and an image as well as the performance of putImageData() here:

http://jsperf.com/canvas-drawimage-vs-putimagedata/3

截至目前, drawImage () putImageData()快得多。上次我听说这不是故意的,浏览器开发人员正在寻求改善性能差距。

As of right now, drawImage() is much faster than putImageData(). Last I heard, this was not intended and the browser developers were looking into improving the performance gap.

这篇关于是putImageData比drawImage快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆