I am developing an application for iPhone using the PhoneGap and I am coding in JavaScript. What I do is that I am downloading an image from the web and encode it into Base64 to store it in my database using the:
dataURL = canvas.toDataURL("image/png");
The stored image is of the form:
data:image/jpeg;base64,ENCODING...
Now, I need when the user is offline, to get the image from the database and display it on the HTML5 canvas item. I have the following code for that:
var canvas = document.getElementById("draw_area");
var context = canvas.getContext('2d');
var myImage = new Image();
myImage.src = dataURL;
myImage.onload = function (){
context.drawImage (myImage, 0, 0);
};
BUT I get an empty canvas even though I check and am sure that the src is the exact base64 encoding I get from the database. Should I do something else first, like decoding and then display the image? If yes, how do I implement that?