Canvas basic knowledge

context: context is an object that encapsulates many drawing functions. The method to obtain this object is var context =canvas.getContext("2d");

Perhaps this 2d has aroused everyone’s imagination. , but I regret to tell you that HTML5 does not provide 3D services.


There are two methods for drawing images using canvas elements, namely

context.fill()//Fill

context.stroke()//Draw the border

style: Before drawing graphics, you must set the drawing style

context.fillStyle//Fill style

context.strokeStyle//Border style

context.lineWidth//Graphic border Width

Color representation:

Directly use the color name: "red" "green" "blue"

Hexadecimal System color value: "#EEEEFF"

rgb(1-255,1-255,1-255)

rgba(1-255,1-255,1-255, transparency)

It is so similar to GDI, so friends who have used GDI should be able to get started quickly


Continuing Learning
||
<!DOCTYPE html> <html> <head>  <meta charset="utf-8">  <title>php中文网</title>  </head> <body> <canvas id="demoCanvas" width="500" height="500"> <p>请使用支持HTML5的浏览器查看本实例</p> </canvas> <!---下面将演示一种绘制矩形的demo---> <script type="text/javascript"> //第一步:获取canvas元素 var canvasDom = document.getElementById("demoCanvas"); //第二步:获取上下文 var context = canvasDom.getContext('2d'); //第三步:指定绘制线样式、颜色 context.strokeStyle = "red"; //第四步:绘制矩形,只有线。内容是空的 context.strokeRect(10, 10, 190, 100); //以下演示填充矩形。 context.fillStyle = "blue"; context.fillRect(110,110,100,100); </script> </body> </html>
submitReset Code