使用Web Worker从文件中获取getImageData [英] Use Web Worker to getImageData from a file

查看:324
本文介绍了使用Web Worker从文件中获取getImageData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从Web Worker中的文件解码图像数据,以便我可以将其传递到主线程并使用putImageData。这大概比调用drawImage要快。

Is it possible to decode the image data from a file in a Web Worker so that I can pass it to the main thread and use putImageData. This is presumably faster than just calling drawImage.

推荐答案

是的。 WebWorker API规范允许您简单地postMessage ImageData和ArrayViews到它或从它。然而,并不是所有的实现当前都启用了afaik。您可能想查看 JSConf'11的此视频,该视频还涉及这个主题。

Yes it is. The WebWorker API specification allows you to simply postMessage ImageData and ArrayViews to and from it. However, not all implementations currently have this enabled afaik. You may want to have a look at this video from JSConf'11 that also touches this topic.

说到这里,putImageData比drawImage慢得多,至少当我们今年早些时候测试他们。有关详细信息,请参见此stackoverflow答案,特别是这个jsPerf测试用例比较putImageData,getImageData,toDataURL和drawImage。

That beeing said, putImageData is much slower than drawImage, at least when I tested them earlier this year. See this stackoverflow answer for details, especially this jsPerf testcase comparing putImageData, getImageData, toDataURL and drawImage.

这篇关于使用Web Worker从文件中获取getImageData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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