HTML5 step by step-extended graphic markup (5)

Source: Internet
Author: User

Draw text:
Similar to drawing a graph, first fill and then stroke
For example:
Context. fillText (text, x, y, maxwidth );
Context. strokeText (text, x, y, maxwidth );

Measure the text width:
TextWidth = context. measureText (text). width;


TextBaseline specifies the vertical alignment mode:
Context. textBaseline = [top | middle | bottom | hanging]


DrawImage:
Context. drawImage (image, dx, dy );
Context. drawImage (image, dx, dy, dw, dh );
Context. drawImage (image, sx, sy, sw, sh, dx, dy, dw, dh );
Parameter Parsing:
Image: The image to be drawn.
X, y: the position in the upper left corner of the image to be drawn.
Width, height: the size of the image to be drawn. Specify these parameters so that the image can be scaled.
SourceX and sourceY: upper left corner of the area to be drawn. These integer parameters are measured in image pixels.
SourceWidth and sourceHeight: the size of the area to be drawn by the image, which is expressed in pixels.
DestX, destY: coordinates of the canvas in the upper left corner of the image area to be drawn.
DestWidth and destHeight: size of the canvas to be drawn in the image area.

Select a region and paste it to the target region:
Image. onload = function (){
Context. drawImage (image, 0, 0 );
Context. drawImage (image, 620,300,375,390, 10,200,250 );
}

How to draw an overlapping Image
Context. globalCompositeOperation = 'mode (source-over, source-in )'

Draw pixels:
GetImageData (): Get image pixels, putImageData (): Write back pixels.


Author: shiyuan17

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.