Which HTML5 built-in object is used to draw on the canvas

青灯夜游
Release: 2022-01-11 11:41:47
Original
2915 people have browsed it

In HTML5, the built-in object getContext() is used to draw on the canvas. getContext() is used to obtain the rendering context and its drawing function. It can return an environment for drawing on the canvas. The syntax is: "Canvas.getContext(contextID)".

Which HTML5 built-in object is used to draw on the canvas

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

Which HTML5 built-in object is used for drawing on the canvas? ()

A.getContent

B.getContext

C.getGraphics

D.getCanvas

Correct answer: B

The getContext() method is used to obtain the rendering context and its drawing functions, and can return an environment for drawing on the canvas. This function takes one parameter, the type of context2d.

Syntax

Canvas.getContext(contextID)
Copy after login

Parameters

  • Parameters contextID specifies the type of drawing you want to draw on the canvas. Currently the only legal value is "2d", which specifies 2D drawing and causes this method to return an environment object that exports a 2D drawing API.

Tip: In the future, if the tag is extended to support 3D drawing, the getContext() method may allow passing a "3d" string argument.

Return value

  • A CanvasRenderingContext2D object, which can be used to draw into the Canvas element.

Description

  • Returns an environment representing the type of environment used to draw. The intention is to provide different environments for different drawing types (2D, 3D). Currently, the only one supported is "2d", which returns a CanvasRenderingContext2D object that implements most of the methods used by a canvas.

Example: Here is the code to get the required context and check if your browser supports the element:

var canvas = document.getElementById("mycanvas");
if (canvas.getContext){
   var ctx = canvas.getContext('2d');
   //在这里绘制代码
   } else {
   //画布不支持的代码在这里
}
Copy after login

Related recommendations:《html video tutorial

The above is the detailed content of Which HTML5 built-in object is used to draw on the canvas. 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
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!