Trying to upload an image to html5 canvas and then launch html5 on Android using Phonegap. Here is my HTML.
<!DOCTYPE HTML> <html> <body> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;"> Your browser does not support the canvas element. </canvas> <script type="text/javascript"> var c=document.getElementById("myCanvas"); var cxt=c.getContext("2d"); var img=new Image() img.src="img_flwr.png" cxt.drawImage(img,0,0); </script> <img src="img_flwr.png"/> </body> </html>
I included the standard img tag to demonstrate the problem.
In Firefox, this page correctly displays the image displayed on the canvas and in the standard img tag.

When I deploy Android emulator using Phonegap, only standard img is displayed.

Both html and .png files are in the assets / www folder of my phonegap project.
How can I display the image on canvas correctly?
EDIT .. Fixed (thanks to Avinash) .. all about timing .. you need to wait until img loads before drawing to .vis canvas
var c=document.getElementById("myCanvas"); var cxt=c.getContext("2d"); var img=new Image() img.src="img_flwr.png"; img.onload = function() { cxt.drawImage(img,0,0); };
android html5 cordova canvas
Michael dausmann
source share