从Node.js中的ArrayBuffer创建映像 [英] Create image from ArrayBuffer in Nodejs
问题描述
我正在尝试从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屋!