Home > Web Front-end > H5 Tutorial > body text

HTML5使用drawImage()方法绘制图像_html5教程技巧

WBOY
Release: 2016-05-16 15:47:34
Original
1900 people have browsed it

一、绘制图像

使用drawImage()方法绘制图像。绘图环境提供了该方法的三个不同版本。
drawImage(image,x,y) : 在canvas中(x,y)处绘制图片。
drawImage(image,x,y,width,height) : 在canvas中(x,y)处绘制图片,并将其缩放到指定的宽度和高度。
drawImage(image,sourceX,sourceY,sourceWidth,sourceHeight,x,y,width,height) : 从图片中切割出一个矩形区域(sourceX,sourceY,sourceWidth,sourceHeight),缩放到指定的宽度和高度,并在canvas中(x,y)绘制出来。

二、HTML5使用drawImage()方法绘制图像_html5教程技巧标签

绘制图片前,还需要将图片加载到浏览器中。这里我们仅仅在canvas标签后面添加一个HTML5使用drawImage()方法绘制图像_html5教程技巧标签。

HTML5使用drawImage()方法绘制图像_html5教程技巧

三、绘制图片

复制代码
代码如下:





HTML5





提示:你的浏览器不支持标签

HTML5使用drawImage()方法绘制图像_html5教程技巧



四、绘制效果
 
五、附上原坦克素材
Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!