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
感謝