Thursday, 15 January 2015

javascript - why save value come "null" (trying to save image in encode64)? -



javascript - why save value come "null" (trying to save image in encode64)? -

i trying save image in encoded64 , value of image local storage .but getting null value why ?

here fiddle: http://jsfiddle.net/sah8w/7/

function getbase64image(img) { // create empty canvas element var canvas = document.createelement("canvas"); canvas.width = img.width; canvas.height = img.height; // re-create image contents canvas var ctx = canvas.getcontext("2d"); ctx.drawimage(img, 0, 0); // data-url formatted image // firefox supports png , jpeg. check img.src // guess original format, aware using "image/jpg" // re-encode image. var dataurl = canvas.todataurl("image/png"); seek { localstorage.setitem("elephant", dataurl); } grab (e) { alert('error') console.log("storage failed: " + e); } //return dataurl.replace(/^data:image\/(png|jpg);base64,/, ""); }

this minor alter prepare issue:

$('#save').click(function(){ var image = new image(); image.src = "https://dl.dropboxusercontent.com/s/t2ywui846zp58ye/plus_minus_icons.png?m="; getbase64image(image); }) working fiddle: http://jsfiddle.net/robertrozas/sah8w/15/ update(get button): http://jsfiddle.net/robertrozas/sah8w/17/

javascript jquery

No comments:

Post a Comment