Drawing an svg containing html in a canvas with safari

后端 未结 2 1586
耶瑟儿~
耶瑟儿~ 2021-02-20 11:02

I\'m trying to create some thumbnails of dynamically created pages for a website, i have found a solution by adding the html in a svg which I then draw on an image inside a canv

2条回答
  •  猫巷女王i
    2021-02-20 11:37

    Basically the solution was to put the mime type(data:image/svg+xml) in the variable containing the svg, this way you don't need to use the blob anymore and then to set the img src with the svg before drawing it to the canvas.

    var canvas = document.getElementById('canvasTest'),
                context = canvas.getContext('2d');
    
                var data = "data:image/svg+xml,"+"" +
                     "" +
                       "
    " + "
    aaaaaaaa
    " + "
    " + "
    " + "
    " ; var img = new Image(); img.src = data; img.onload = function() { context.drawImage(img, 100, 100); }; context.translate(canvas.width / 2, canvas.height / 2); context.scale(0.4, 0.4);

提交回复
热议问题