Detailed explanation of code examples for getting started with HTML5 canvas (picture)

黄舟
Release: 2017-03-15 16:11:09
Original
1611 people have browsed it

1) HTMLCanvasElementMembers of object:

# #height——corresponds to the heightattributeof the canvas element;

##width——Corresponds to the width attribute of the canvas element;

# getContext( )— — Return the drawingcontext for the canvas;

##2) Draw the rectangle:

## fillRect(x,y,w,h)——Draw a solid rectangle;

# strokeRect(x,y,w,h)——Draw a hollow rectangle;

clear

Rect(x,y,w,h)——Clear the specified rectangle;

3) Set canvas drawingstatus:


lineWidth——Get or set the width of the line (default value is 1.0);

lineJoin——Get or set The style when the line is connected to the graphic (default value is miter);


fillStyle——Get or set for solid The style of the graphic (default value is black);

strokeStyle - Gets or sets the style used for lines(default value is black );

#

 您的浏览器不支持canvas! 
Copy after login
Copy after login
 您的浏览器不支持canvas! 
Copy after login
Copy after login

 您的浏览器不支持canvas! 
Copy after login
Copy after login

4) Use gradient


createLinearGradient (x0,y0,x1,y1)——Create a linear gradient and return a CanvasGradient object;


createRadialGradient(x0,y0,r0,x1,y1,r1 )——Create a radial gradient and return a CanvasGradient object;

CanvasGradient object

Methods:

## addColorStop(<position>, )——Add a gradient line to the gradient A solid color;

##

 您的浏览器不支持canvas! 
Copy after login
rrree

 您的浏览器不支持canvas! 
Copy after login
Copy after login


 您的浏览器不支持canvas! 
Copy after login
Copy after login


5)使用图案

createPattern( ,int2)——创建图案,指定图案文件的来源和重复方式;

int2的值是指定重复样式:分别有repeat、repeat-x、repeat-y、no-repeat;

 您的浏览器不支持canvas!  
Copy after login
Copy after login

6)保存和恢复状态

save()——保存绘制状态属性的值,并把它们推入状态栈;

restore()——取出状态栈的第一组值,用它们来设置绘制状态;

 您的浏览器不支持canvas!  

Copy after login
Copy after login


7)绘制图像

drawImage方法——在画布上绘制图像,指定一个img、canvas或video元素作为来源;

 您的浏览器不支持canvas!  
Copy after login
Copy after login


  您的浏览器不支持;  

您的浏览器不支持;
Copy after login
 
Copy after login



The above is the detailed content of Detailed explanation of code examples for getting started with HTML5 canvas (picture). For more information, please follow other related articles on the PHP Chinese website!

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
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!