2016-07-22 49 views
2

我想构建一个演示,它是一个node.js C++插件。在node.js中我得到一个位图,它是ARGB格式的,我需要将它传递给html5画布。我试图找到最有效的方法来做到这一点,因为它很痛苦地慢。如何将图像数据从node.js传输到html5画布?

目前我做到以下几点:

--- in node.js --- 
- Convert ARGB to RGBA (because ImageData accepts that format) 
- Create v8::ArrayBuffer (wrapper over the underlying buffer) 
- Create v8::Uint8ClampedArray (wrapper over the array buffer) 
- Return an object which has the Uint8ClampedArray, width and height 

--- in the browser --- 
- Get the result from my function 
- Create ImageData instance with the specified width and height 
- Loop over all bytes in the Uint8ClampedArray and copy them to the image data 
- context.putImageData(image_data, 0, 0); 

我敢肯定,必须有这样做更优化的方式。以某种方式保存插件中的缓冲区并不是问题,但我想至少避免逐个字节地拷贝缓冲区到图像数据。

我也不确定为什么如果我尝试使用带有Uint8ClampedArray的ImageData构造函数作为第一个参数爆炸。在这种情况下,我只是得到: v8 :: Object :: GetAlignedPointerFromInternalField()。错误:没有一个SMI

感谢

回答

0

您可以使用resterize js在画布上的数据绑定。我用它可以快速处理大图像。