Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an image in Dart

Tags:

dart

I'm trying out the Dart Language and HTML5 Canvas element, but I'm stuck with one problem. I don't know how to load an image in Dart. I can get CanvasRenderingContext2D and with this I can call fillText() and fillRect() and everything works, but I am trying to figure out how to load an Image and draw with drawImage.

like image 650
narahd Avatar asked Jul 22 '12 09:07

narahd


1 Answers

Create and load the image

ImageElement image = new ImageElement(src: "my_image.png");
image.onLoad.listen((e) {
    // Draw once the image is loaded
});

Draw the above image on the canvas after it is loaded

context.drawImage(image, destX, destY);
like image 169
Ali Akbar Avatar answered Oct 24 '22 19:10

Ali Akbar