HTML5 Canvas Globalcompositeoperation Drawing type explanation

Source: Internet
Author: User

We always draw one graph on top of another, and in most cases this is not enough. It is, for example, subject to the drawing order of the graph. However, we can use globalCompositeOperation attributes to change these practices.
globalCompositeOperation = type
Not only can we draw new graphics behind the existing graphs, we can also use them to cover and clear clearRect some areas (much more powerful than the method).

typeis one of the following 12 string values:

Note: In all the examples below, the blue squares are drawn first, i.e. "existing canvas content", and the red circle is drawn later, i.e. "new shape".

Source-over (default)

This is the default setting and the new graphic will be overwritten with the original content.

Destination-over

New graphics are drawn under the original content.

Source-in

The new graphic will only appear in the part that overlaps with the original content. All other areas become transparent.

Destination-in

The portion of the original content that overlaps with the new shape is retained, and the other areas become transparent.

Source-out

The result is that only the parts of the new drawing that do not overlap the original content are drawn.

Destination-out

Portions of the original content that do not overlap the new shapes are retained.

Source-atop

The parts of the new drawing that overlap with the original content are drawn and overlaid on the original content.

Destination-atop

Portions of the original content that overlap new content are retained and new graphics are drawn under the original content

Lighter

The overlapping portions of the two graphs are added to the color processing.

Darker

The overlapping portions of the two graphs are treated as subtractive.

Xor

The overlapping parts become transparent.

Copy

Only new graphics are preserved and others are erased.

Note: The copy and darker attribute values are temporarily invalid on Gecko 1.8 browsers (Firefox 1.5 betas, etc.).

HTML5 Canvas Globalcompositeoperation Drawing type explanation

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.