Javascript/HTML5 using image to fill canvas

后端 未结 1 1372
不思量自难忘°
不思量自难忘° 2021-01-02 23:08

I\'m trying to get an image to fill up my canvas. Here is the code I\'m trying:

var blueprint_background = new Image();
blueprint_background.src = \'images/         


        
相关标签:
1条回答
  • 2021-01-02 23:52

    You have to wait until the image loads, use the image's onload property to know when it loads.

    var blueprint_background = new Image();
    blueprint_background.src = 'images/blueprint_background.png'; 
    blueprint_background.onload = function(){
        var pattern = context.createPattern(this, "repeat");
        context.fillStyle = pattern;
        context.fill();
    };
    
    0 讨论(0)
提交回复
热议问题