Home  >  Article  >  Web Front-end  >  Draw SVG files on HTML5 canvas

Draw SVG files on HTML5 canvas

WBOY
WBOYforward
2023-09-15 15:09:02859browse

Draw SVG files on HTML5 canvas

To draw HTMLImageElements on a canvas element, use the drawImage() method. This method defines an Image variable using src="mySVG.svg" and uses drawImage when loading.

var myImg = new Image();
myImg.onload = function() {
   ctx.drawImage(myImg, 0, 0);
}
img.src = "http://www.example.com/files/sample.svg ";

The above is the detailed content of Draw SVG files on HTML5 canvas. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete