从Node.js中的ArrayBuffer创建映像 [英] Create image from ArrayBuffer in Nodejs

查看:249
本文介绍了从Node.js中的ArrayBuffer创建映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从ArrayBuffers的块创建图像文件.

I'm trying to create an image file from chunks of ArrayBuffers.

all= fs.createWriteStream("out."+imgtype);

for(i=0; i<end; i++){
    all.write(picarray[i]);
}

all.end();

其中,picarray包含ArrayBuffer块.但是,出现错误
TypeError: Invalid non-string/buffer chunk.

如何将ArrayBuffer块转换为图像?

where picarray contains ArrayBuffer chunks. However, I get the error
TypeError: Invalid non-string/buffer chunk.

How can I convert ArrayBuffer chunks into an image?

推荐答案

您是否尝试过先将其转换为node.js. Buffer? (这是本机的node.js Buffer接口,而ArrayBuffer是浏览器的接口,并且不完全支持node.js的写操作.)

Have you tried first converting it into a node.js. Buffer? (this is the native node.js Buffer interface, whereas ArrayBuffer is the interface for the browser and not completely supported for node.js write operations).

与此类似的东西应该会有所帮助:

Something along the line of this should help:

all= fs.createWriteStream("out."+imgtype);

for(i=0; i<end; i++){
    var buffer = new Buffer( new Uint8Array(picarray[i]) );
    all.write(buffer);
}
all.end();

这篇关于从Node.js中的ArrayBuffer创建映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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