问题
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