简体   繁体   中英

Drawing image on the canvas using excanvas

I am using excanvas.js library for supporting canvas features in IE(below 9) browsers . The problem I am facing currently is that excanvas expects image as the first argument of the drawImage() method. I found that it will not support another canvas or video as the first argument. What is a work around for achieving this functionality? My code is like this.

    var canvas1 = document.getElementById("canvas1"); // Get the first canvas Element
    var canvas2 = document.getElementById("canvas2"); // Get the second canvas element
    if (typeof G_vmlCanvasManager != 'undefined') {
        canvas1 = G_vmlCanvasManager.initElement(canvas1); // Initialise with excanvas
        canvas2 = G_vmlCanvasManager.initElement(canvas2);
    }    

    if (canvas1.getContext) {
        var ctx1 = canvas1.getContext("2d");
        var ctx2 = canvas2.getContext("2d");
        var img = new Image();
        img.onload = function () {
            ctx1.drawImage(this, 0, 0, 200, 200); // Draw the image on first canvas
            ctx2.drawImage(canvas1, 0, 0, 200, 200); // Draw the image on to the second canvas using the first canvas
        }
        img.src = "image1.jpg";        
    }

It is not working in Ie8 and below browsers. How can solve this problem?

I'd try something like this:

function canvasToImage( canvas ) {
    var img = new Image();
    img.src = canvas.toDataURL();
    return img;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM