• <tfoot id='doNDo'></tfoot>
    1. <i id='doNDo'><tr id='doNDo'><dt id='doNDo'><q id='doNDo'><span id='doNDo'><b id='doNDo'><form id='doNDo'><ins id='doNDo'></ins><ul id='doNDo'></ul><sub id='doNDo'></sub></form><legend id='doNDo'></legend><bdo id='doNDo'><pre id='doNDo'><center id='doNDo'></center></pre></bdo></b><th id='doNDo'></th></span></q></dt></tr></i><div id='doNDo'><tfoot id='doNDo'></tfoot><dl id='doNDo'><fieldset id='doNDo'></fieldset></dl></div>

      • <bdo id='doNDo'></bdo><ul id='doNDo'></ul>

      <small id='doNDo'></small><noframes id='doNDo'>

        <legend id='doNDo'><style id='doNDo'><dir id='doNDo'><q id='doNDo'></q></dir></style></legend>

        将字节数组转换为图像 Node.js

        Byte array into an image Node.js(将字节数组转换为图像 Node.js)

      1. <small id='aSjs1'></small><noframes id='aSjs1'>

        • <bdo id='aSjs1'></bdo><ul id='aSjs1'></ul>

            <tbody id='aSjs1'></tbody>

          <tfoot id='aSjs1'></tfoot>

                <legend id='aSjs1'><style id='aSjs1'><dir id='aSjs1'><q id='aSjs1'></q></dir></style></legend>

                  <i id='aSjs1'><tr id='aSjs1'><dt id='aSjs1'><q id='aSjs1'><span id='aSjs1'><b id='aSjs1'><form id='aSjs1'><ins id='aSjs1'></ins><ul id='aSjs1'></ul><sub id='aSjs1'></sub></form><legend id='aSjs1'></legend><bdo id='aSjs1'><pre id='aSjs1'><center id='aSjs1'></center></pre></bdo></b><th id='aSjs1'></th></span></q></dt></tr></i><div id='aSjs1'><tfoot id='aSjs1'></tfoot><dl id='aSjs1'><fieldset id='aSjs1'></fieldset></dl></div>
                • 本文介绍了将字节数组转换为图像 Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个很长的字节数组,数字从 0 到 255,而且我知道它是一个图像,所以 我怎样才能像文件一样保存它? 我尝试了很多东西,但没有成功.
                  图像已创建但无法打开,因为它已损坏.

                  文件 .js

                  I have a long array of bytes, with numbers from 0 to 255, and I know it's an image, so how can I save it like a file? I have tried a lot of things, but not success.
                  The image is created but won't open because it's damaged.

                  File .js

                  function saveImage(filename, data){
                    //Data = [1,6,2,23,255,etc]
                    var wstream = fs.createWriteStream(ARTWORK_PATH+filename);
                     for (var i = 0; i < data.length; i++) {
                         wstream.write(data[i].toString('base64'));
                     }
                     wstream.end();
                  }
                  

                  推荐答案

                  我解决了这个问题!

                  就像使用缓冲区一样简单...

                  It was as simple as use a buffer...

                  function saveImage(filename, data){
                    var myBuffer = new Buffer(data.length);
                    for (var i = 0; i < data.length; i++) {
                        myBuffer[i] = data[i];
                    }
                    fs.writeFile(ARTWORK_PATH+filename, myBuffer, function(err) {
                        if(err) {
                            console.log(err);
                        } else {
                            console.log("The file was saved!");
                        }
                    });
                  }
                  saveImage("image.jpg", [0,43,255,etc]);
                  

                  这篇关于将字节数组转换为图像 Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                  <tfoot id='HciGH'></tfoot>

                • <small id='HciGH'></small><noframes id='HciGH'>

                • <i id='HciGH'><tr id='HciGH'><dt id='HciGH'><q id='HciGH'><span id='HciGH'><b id='HciGH'><form id='HciGH'><ins id='HciGH'></ins><ul id='HciGH'></ul><sub id='HciGH'></sub></form><legend id='HciGH'></legend><bdo id='HciGH'><pre id='HciGH'><center id='HciGH'></center></pre></bdo></b><th id='HciGH'></th></span></q></dt></tr></i><div id='HciGH'><tfoot id='HciGH'></tfoot><dl id='HciGH'><fieldset id='HciGH'></fieldset></dl></div>
                          <tbody id='HciGH'></tbody>

                          <legend id='HciGH'><style id='HciGH'><dir id='HciGH'><q id='HciGH'></q></dir></style></legend>
                            <bdo id='HciGH'></bdo><ul id='HciGH'></ul>