Home > Web Front-end > HTML Tutorial > Draw a data URL as an image on HTML5 canvas

Draw a data URL as an image on HTML5 canvas

WBOY
Release: 2023-09-17 23:33:15
forward
1179 people have browsed it

Draw a data URL as an image on HTML5 canvas

If you have a data URL, you can create an image on the canvas. This can be done as shown in the following code snippet -

var myImg = new Image;
myImg.src = strDataURI;
Copy after login

drawImage() method draws an image, canvas or video onto the canvas. The drawImage() method can also draw a portion of the image, and/or increase/decrease the image size.

The code given below also works for this sequence - create image, set onload to use new image, then set src -

// load image from data url
Var Obj = new Image();
Obj.onload = function() {
   context.drawImage(myImg, 0, 0);
};
Obj.src = dataURL;
Copy after login

The above is the detailed content of Draw a data URL as an image on HTML5 canvas. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template