如何将图像数据从node.js传输到html5canvas?

我正在尝试构build一个演示,它是一个node.js C ++插件。 在node.js我得到一个位图,这是在ARGB格式,我需要将其传递到HTML5canvas。 我正在试图find最有效的方式来做到这一点,因为它是痛苦的缓慢。

目前我做了以下几点:

--- 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); 

我很确定,一定有更好的方法来做到这一点。 以某种方式保持插件中的缓冲区不是问题,但我想至less避免缓冲区的逐字节拷贝到图像数据。

我也不知道为什么如果我尝试使用的ImageData构造函数,作为第一个参数Uint8ClampedArray爆炸。 在这种情况下,我只是越来越:v8 :: Object :: GetAlignedPointerFromInternalField()。 错误:不是Smi

谢谢

您可以使用resterize js来绑定canvas中的数据。 我使用它,即使对于大尺寸的图像,它的工作速度也很快。