如何写入Uint8ClampedArray? [英] How to write to Uint8ClampedArray?

查看:2317
本文介绍了如何写入Uint8ClampedArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个节点插件,它接受HTML画布图像数据,类型为 Uint8ClampedArray 。我想修改这个数组的内容而不需要任何额外的副本。

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.

我找到的最佳候选者是 v8 :: Object :: Set 方法 (v8 :: Object是Uint8ClampedArray的继承层次结构中的类)

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

但是,该方法需要将v8 :: Context对象的句柄作为第一个参数。我不知道怎么做。

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

我搜索了github repos并在Webkit中找到了直接将Uint8ClampedArray指针转换为原始数组指针的代码,但这并不是似乎可以通过公共v8 API。

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.

推荐答案

好的,想通了。

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

这篇关于如何写入Uint8ClampedArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆