Draw SVG File on HTML5 Canvas



To draw HTML Image Elements on a canvas element, use the drawImage() method. This method defines an Image variable with src = "mySVG.svg", and use drawImage on load.

var myImg = new Image();
myImg.onload = function() {
   ctx.drawImage(myImg, 0, 0);
}
img.src = "http://www.example.com/files/sample.svg ";
Updated on: 2023-11-24T01:25:51+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started