Name
CRC.globalCompositeOperation — how colors are combined on the canvas
Synopsis
String globalCompositeOperation
Description
This property specifies how source pixels being rendered onto the
canvas are combined (or “composited”) with the destination pixels that
already exist in the canvas. This property is typically useful only when
you are working with partially transparent colors or have set the
globalAlpha
property. The default is value is
“source-over”. Other commonly used values are “destination-over” and
“copy”.
The following table lists the allowed property values and their
meanings. In the third column, the word source
refers to the pixels being drawn onto the canvas, the word
destination refers to the existing pixels on the
canvas, and the word result refers to the pixels
that result from the combination of the source and destination. The
second column shows the formula for computing a result pixel from a
source pixel S
and a destination pixel
D
along with the alpha channel (the opacity) of the
source pixel αs and the alpha channel of the
destination αd:
Value | Formula | Meaning |
---|---|---|
copy | S | Draw the source pixel, ignoring the destination pixel. |
destination-atop | (1-αd)S +
αsD | Draw the source pixel underneath the destination. If the source is transparent, the result is also transparent. |
destination-in | αsD | Multiply the destination pixel by the opacity of the source pixel, but ignore the color of the source. |
destination-out | (1-αs)D | The destination pixel is made transparent when the source is ... |
Get Canvas Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.