Note that there are some explanatory texts on larger screens.

plurals
  1. POnode.js encoding images to save to file in webOS
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5874521/save-html5-canvas-element-to-file-using-webos">save html5 canvas element to file using webos</a> </p> </blockquote> <p>here img variable is extracted from using Open Source Png Generation code here ..</p> <p>i have used this library and manipulated on my canvas image data pixel array</p> <pre><code> EditorAssistant.prototype.getDataURL = function(width,height,data){ var p = new PNGlib(height, width, 256); // construcor takes height, weight and color-depth var background = p.color(0, 0, 0, 0); // set the background transparent for (var i = 0, n = data.length; i &lt; n; i += 4) { var x = i * 10; var y = Math.sin(i) * Math.sin(i) * 50 + 50; // use a color triad of Microsofts million dollar color p.buffer[p.index(Math.floor(x), Math.floor(y))] = p.color(data[i], data[i+1], data[i+2]); } return 'data:image/png;base64,'+p.getBase64() ; } </code></pre> <p>what are x and y here i dont know i just want to out my pixel array to this PNG</p> <p>honestly speaking i am newbie to node.js. i am just having an hit and trial APProach... imgdata generated above is passed to this code as data.. there are two issues with the code 1: it creates a file with size equal to number of bytes written to the file,but it is empty i am sure it is some encoding issue... 2:this code does not save the actual canvas pixel array in the file it creates...</p> <pre><code>var fs = IMPORTS.require('fs'); var path = IMPORTS.require('path'); var buff = new Buffer(data,'binary').toString('base64'); path.exists('images/', function(exists ){ if (exists) { fs.open('images/icon.png', 'w', 666, function( e, id ) { fs.write( id, buff, null, 'binary', function(err,written){ if(err) callback({ error: false, reply: err }); if(written){ callback({ error: false, reply: buff.toString() }); } fs.close(id, function(){ callback({ error: false, reply: 'closed' }); }); }); }); } else { callback({ error: true, reply: 'File did not exist.' }); } } }) </code></pre> <p>help me plz thnks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload