Canvas related knowledge in html5 (1) concepts and definitions, html5canvas

Source: Internet
Author: User

Canvas related knowledge in html5 (1) concepts and definitions, html5canvas
What is Canvas?

HTML5 canvas elements use JavaScript to draw images on webpages.

A canvas is a rectangular area that allows you to control each pixel.

Canvas has multiple ways to draw paths, rectangles, circles, characters, and add images.

<Canvas> A label is only a graphical container and does not have its own behavior. You need to define an API to support script-based client plotting.

Create a Canvas Element

The canvas code is very simple. It defines an ID and its width and height. It must be emphasized that the width and height of the canvas must be written on the element. If the style is defined, the ratio of the canvas image cannot be changed.

<Canvas id = "myCanvas" width = "200" height = "100"> </canvas>
How to Use <canvas> to mark a drawing

Most Canvas drawing APIs are not defined on the <canvas> element, but on the getContext () method of the Canvas.Drawing EnvironmentObject.

This is obtained through the getContext () method of the Canvas object and passing the string "2d" as a unique parameter to it.

<Script type = "text/javascript"> var c = document. getElementById ("myCanvas"); var cxt = c. getContext ("2d"); cxt. fillStyle = "# FF0000"; cxt. fillRect (,); </script>

Tip: in the future, if the <canvas> label is extended to support 3D drawing, the getContext () method may allow passing a "3d" string parameter.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.