Canvas Translation & amp; scaling, canvas

Source: Internet
Author: User

Canvas Translation & scaling, canvas

1. Translation
Canvas is actually just a wrapper. The main part that really plays a role is the 2D rendering context, which is where we actually draw images.
However, 2D rendering context is a screen-based standard rendering platform. It uses the Cartesian coordinate system of the screen and uses the (0, 0) coordinate in the upper left corner as the origin.
The x coordinate value increases when you move to the right, and the y coordinate value increases when you move down.
After learning about the coordinate system, we can move and process the positions of the images as much as possible!
Translation, that is, the process of moving a graph from one coordinate point to another by referring to the origin point (0, 0) of the 2D rendering context!
Usage: The translate (x, y) parameters add x unit values to the left and y unit values to the coordinates of the origin.

<! DOCTYPE html> 

It is not difficult to see that once the drawing status of canvas is set, it will affect the painting attributes of all subsequent elements!
This is because they are all operated in the 2D rendering context, rather than only for the drawn image.

 

2. Zoom
Usage: scale (x, y );
Adjust the size of an element in the 2D context. The difference from the translation is that the (x, y) parameter is a zoom factor, not a pixel value.
By using this method alone, all subsequent elements are scaled in multiples. This is definitely not what you want!
Therefore, before scaling, call the save () method to save the drawing status. After the current element is scaled,
We can call the restore () method to restore the drawing to the previous state, so that only the current element can be scaled!

<! DOCTYPE html> 

 

 

Communication Group: 225443677

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.