How to write to Uint8ClampedArray?

£可爱£侵袭症+ 提交于 2020-01-24 21:58:30

问题


I'm writing a node addon which accepts HTML canvas Image data, that's of type Uint8ClampedArray. I want to modify the the contents of this array without any extra copy.

The best candidate I've found is the v8::Object::Set method (v8::Object being a class in Uint8ClampedArray's inheritance hierarchy)

However that method requires a handle to v8::Context object as first argument. I don't know how to get that.

I've searched through github repos and found code inside Webkit that directly casts Uint8ClampedArray pointers to raw array pointers, however that doesn't seem to be possible through the public v8 API.


回答1:


Ok, figured it out.

v8::Local<v8::Uint8ClampedArray> arr;
unsigned char *data = (unsigned char *)arr->Buffer()->GetContents().Data();


来源:https://stackoverflow.com/questions/42139643/how-to-write-to-uint8clampedarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!