Canvas draw text, canvas draw

Source: Internet
Author: User

Canvas draw text, canvas draw

<! DOCTYPE html> 

 

Function draw (id) {var canvas = document. getElementById (id); // obtain the canvas object var context = canvas. getContext ('2d '); // obtain the context and set it to 2d context. fillStyle = "green"; // specifies the rectangular color context of the canvas size. fillRect (800,300,); // draw the rectangular context of the canvas size. fillStyle = "white"; // set the text fill color context. strokeStyle = "white"; // set the text border color context. font = "bold 40px '文 ',' '"; // set the font width, size, and style. [multiple options ]. // Vertical text alignment. The default value is alphabetic // Bottom Alphabetic // --------------------- Middle -------------------------- // Top Hanging // context. textBaseline = 'alphabetic '; // The attribute values can be top (top alignment), hanging (suspension), middle (center alignment), bottom (bottom alignment), and alphabetic (default value. Context. textBaseline = 'hanging'; // sets the horizontal alignment of text, the default value is start/| // | start/end | // | left/center/right | // context. textAlign = 'start'; // The attribute value can be set to start, end, left, right, and center context. fillText ("Welcome to Hua Shuai's blog",); context. strokeText ("HTML5 + CSS3 practices", 200,130); context. fillText ("getting started, thank you. ", 380,190); context. fillText ('20140901', 123456789987654321123456789987654321123456789987654321123456789987654321123456789987654321 )}

 

The fillText method or StrokeText method that can be used to draw a font.
The fillText method is used to draw strings by filling them.
Context. fillText (text, x, y, [maxwidth]);

The strokeText method draws strings using outlines.
Context. strokeText (text, x, y, [width]);

The first parameter text indicates the text to be drawn, the second parameter x indicates the abscissa of the start point to be drawn, and the third parameter y indicates the ordinate of the start point of the text to be drawn, the fourth parameter, maxwidth, is an optional parameter, indicating the maximum width of text displayed to prevent text overflow.

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.