Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
window.onload = function ()
{
        var img = new Image();
        img.src = "images/rope.png";
        canvas = document.createElement("canvas");
        canvas.id = "canvasTest";
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        canvas.style.position = "absolute";
        canvas.style.border = "1px solid";
        context = canvas.getContext("2d");
        context.drawImage(img, 0, 0);
        document.body.appendChild(canvas);
    }
Posted
Comments
Graham Breach 9-Apr-13 4:27am    
It looks OK, except you're not waiting for the image to load before drawing with it. "canvas" and "context" should be declared as variables somewhere too.
NachiketM 9-Apr-13 5:45am    
Thanks, it helped. I loaded the image and drawn, then it succeed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900