html2canvas Uncaught (in promise) undefined

前端 未结 2 699
春和景丽
春和景丽 2021-01-27 13:07

I have a html tag canvas.


I can draw on it successfully, and it looks really good, as i wanted to

2条回答
  •  无人共我
    2021-01-27 13:36

    html2canvas is used for converting html code into a canvas view. If I am understanding correctly, you just want to get an image from the canvas so html2canvas is not needed. Simply just use Canvas2Image on it's own.

    Example (blue is the image, red is the canvas):

    // Example canvas with circle
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    ctx.beginPath();
    ctx.arc(95,50,40,0,2*Math.PI);
    ctx.stroke();
    
    
    var image = Canvas2Image.convertToPNG(c); // Returns HTMLImageElement 
    
    $("#canvasImg").attr('src', image.src); // Set the src of our output image to the src of the HTMLImageElement
    
    
    
    
    
    
    
    

提交回复
热议问题