javascript - Creating a PNG from uncompressed raw PNG data -
i using android screenshot library capture screenshots. want show screenshot in web browser.
i have written small socket app on pc connects android phone , encode captured screenshot base64.
string base64 = base64.getencoder().encodetostring(bytes);
this base64 being sent web page on websocket. below html/js code should draw image on canvas. have stored base64 image data in text file test purpose.
<div style="background: aqua; width: 500px; height: 660px;"> <canvas style="width: 480px; height: 640px;" id="sim"> </canvas> </div> <script type="text/javascript"> var ctx; var width = 480; var height = 640; (function start() { ctx = document.getelementbyid("sim").getcontext("2d"); loadfromfile(); })(); function loadimage(data) { var image = new image(); image.onload = function() { //this part never executes ctx.drawimage(image, 0, 0); console.log("images loaded!"); } image.src = "data:image/png;base64," + data; } function loadfromfile() { //please data **https://app.box.com/s/e19ww51fd37h4sy8getjnag31ud6tpp9** var file = "imagefile.txt"; var rawfile = new xmlhttprequest(); rawfile.open("get", file, true); rawfile.onreadystatechange = function() { if (rawfile.readystate === 4) { if (rawfile.status === 200 || rawfile.status == 0) { var data = rawfile.responsetext; console.log("data loaded: " + data.length); loadimage(data); } } } rawfile.send(null); } </script>
for convenience, here jsfiddle of same code.
please point right algorithm how generate png raw uncompressed data. code sample great ;)
thanks
public static string encodetobase64(bitmap image) { bitmap immagex=image; bytearrayoutputstream baos = new bytearrayoutputstream(); immagex.compress(bitmap.compressformat.jpeg, 100, baos); byte[] b = baos.tobytearray(); string imageencoded = base64.encodetostring(b,base64.default); log.e("look", imageencoded); return imageencoded; } public static bitmap decodebase64(string input) { byte[] decodedbyte = base64.decode(input, 0); return bitmapfactory.decodebytearray(decodedbyte, 0, decodedbyte.length); }
Comments
Post a Comment