cordova - Save image locally from img tag with PhoneGap -
i'm quite new phonegap.
i'm using 3.1 version camera feature. 've saved image file camera.getpicture device storage, have new task: after loading camera function, manipulate image dircetly canvas tag, , so..
how can save image locally img tag (that contains manipulated image), device storage?
thanks in advance, appreciated!
i can think of way, need search them, can give rough idea.
idea base64 image string > send native code > convert again image > save it
you can put image in canvas
, convert image base64 encoded string.
function convertimgtobase64(url, callback, outputformat){ var canvas = document.createelement('canvas'); var ctx = canvas.getcontext('2d'); var img = new image; img.crossorigin = 'anonymous'; img.onload = function(){ canvas.height = img.height; canvas.width = img.width; ctx.drawimage(img,0,0); var dataurl = canvas.todataurl(outputformat || 'image/png'); callback.call(this, dataurl); // clean canvas = null; }; img.src = url; } convertimgtobase64(imageurl, function(base64img){ //base64img )
sent image string native code. how! search in google. there way called appview or can write custom plugin.
next convert image string image
fileoutputstream fos = null; try { if (base64imagedata != null) { fos = context.openfileoutput("imagename.png", context.mode_private); byte[] decodedstring = android.util.base64.decode(base64imagedata, android.util.base64.default); fos.write(decodedstring); fos.flush(); fos.close(); } } catch (exception e) { } { if (fos != null) { fos = null; } }
convert string in base64 image , save image
and save using native code.
Comments
Post a Comment