Clark
Clark

Reputation: 153

How to determine if Image is already drawn in HTML Canvas

supposed i have an image /site/image1.jpg upon drawing this to the canvas it would be something like this.

var image = new Image();
image.src = "/site/image1.jpg";
image.onload = function(){
    context.drawImage(image,x,y);
}

Assuming my internet connection is so slow how would i know that the image was already drawn on the canvas?

Thanks.

Upvotes: 3

Views: 1678

Answers (1)

Blindman67
Blindman67

Reputation: 54026

To workout if the image has been draw keep a flag or mark the image.

var image = new Image();
image.src = "blah.foo";
image.drawn = false;  // Add a property to indicate if the image has been drawn
image.onload = function(){
    ctx.drawImage(image,0,0);
    image.drawn = true;  // flag it as drawn
}
// then later you if you want to know if its been drawn
if(image.drawn){
    console.log("Yes its been drawn.");
}

Upvotes: 1

Related Questions