Canvas for HTML5 labels

Source: Internet
Author: User

Canvas for HTML5 labels
1: 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.


2. Create a Canvas element.
Add a canvas element to the HTML5 page.
Specify the element id, width, and height:



3: Draw using JavaScript
The canvas element itself has no plotting capability. All the painting work must be completed inside JavaScript:
// Draw a line segment
// Obtain the canvas DOM
Var c = document. getElementById ("myCanvas ");
Console. log (c );
// Set the plotting environment CanvasRenderingContext2D
Var cxt = c. getContext ("2d ");
Console. log (cxt );
// Set the paint width
Cxt. lineWidth = 10;
// Set the paint brush color
Cxt. strokeStyle = "# ff9900 ";
// Set the stroke position
Cxt. moveTo (20, 20 );
// Set the Mobile mode
Cxt. lineTo (100, 20 );
// Draw a line
Cxt. stroke ();


Note: For Path graphics, you must first start the path and draw the end path (Closed Path)
Cxt. beginPath ();
Cxt. closePath ();
Prevents association between multiple images.

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.