What does PorterDuff.Mode mean in android graphics.What does it do?

AndroidGraphicsPorter Duff

Android Problem Overview


I would like to know what PorterDuff.Mode means in android graphics.

I know that it is a transfer mode.

I also know, that it has attributes such as DST_IN, Multiply etc.

Android Solutions


Solution 1 - Android

Here's an excellent article with illustrations by a Google engineer:

http://ssp.impulsetrain.com/porterduff.html

PorterDuff is described as a way of combining images as if they were "irregular shaped pieces of cardboard" overlayed on each other, as well as a scheme for blending the overlapping parts.

The default Android way of composing images is http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_OVER">PorterDuff.Mode.SRC_OVER</a>;, which equates to drawing the source image/color over the target image. In other words, it does what you would expect and draws the source image (the one you're drawing) on top of the destination image (the canvas) with the destination image showing through to the degree defined by the source image's alpha.

PorterDuff infographic from the article

You can use the key below to understand the algebra that http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html">the Android docs use to describe the other modes (see http://ssp.impulsetrain.com/porterduff.html">the article for a fuller desription with similar terms).

  • Sa Source alpha
  • Sc Source color
  • Da Destination alpha
  • Dc Destination color

Where alpha is a value [0..1], and color is substituted once per channel (so use the formula once for each of red, green and blue)

The resulting values are specified as a pair in square braces as follows.

[<alpha-value>,<color-value>]

Where alpha-value and color-value are formulas for generating the resulting alpha chanel and each color chanel respectively.

Solution 2 - Android

It defines how to compose images based on the alpha value. See more here http://en.wikipedia.org/wiki/Alpha_compositing

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrogerstoneView Question on Stackoverflow
Solution 1 - AndroidPhasmalView Answer on Stackoverflow
Solution 2 - AndroidyoahView Answer on Stackoverflow