The problem is that the image hasn't loaded by the time you call drawImage (as opposed to when it is embedded in the page and loads before the dart code runs). You should listen for the onLoad stream and only draw the image once it is loaded:
ImageElement img = new ImageElement(src: "img.png");
img.onLoad.listen((value) => context.drawImage(img, 0, 0));