PorterDuff.Mode
public
static
final
enum
PorterDuff.Mode
extends Enum<PorterDuff.Mode>
java.lang.Object | ||
↳ | java.lang.Enum<android.graphics.PorterDuff.Mode> | |
↳ | android.graphics.PorterDuff.Mode |
The name of the parent class is an homage to the work of Thomas Porter and Tom Duff, presented in their seminal 1984 paper titled "Compositing Digital Images". In this paper, the authors describe 12 compositing operators that govern how to compute the color resulting of the composition of a source (the graphics object to render) with a destination (the content of the render target).
"Compositing Digital Images" was published in Computer Graphics Volume 18, Number 3 dated July 1984.
Because the work of Porter and Duff focuses solely on the effects of the alpha channel of the source and destination, the 12 operators described in the original paper are called alpha compositing modes here.
For convenience, this class also provides several blending modes, which similarly define the result of compositing a source and a destination but without being constrained to the alpha channel. These blending modes are not defined by Porter and Duff but have been included in this class for convenience purposes.
Diagrams
All the example diagrams presented below use the same source and destination images:
![]() |
![]() |
The order of drawing operations used to generate each diagram is shown in the following code snippet:
Paint paint = new Paint(); canvas.drawBitmap(destinationImage, 0, 0, paint); PorterDuff.Mode mode = // choose a mode paint.setXfermode(new PorterDuffXfermode(mode)); canvas.drawBitmap(sourceImage, 0, 0, paint);
Alpha compositing modes
![]() Source |
![]() Source Over |
![]() Source In |
![]() Source Atop |
![]() Destination |
![]() Destination Over |
![]() Destination In |
![]() Destination Atop |
![]() Clear |
![]() Source Out |
![]() Destination Out |
![]() Exclusive Or |
Blending modes
Compositing equations
The documentation of each individual alpha compositing or blending mode below provides the exact equation used to compute alpha and color value of the result of the composition of a source and destination.
The result (or output) alpha value is noted αout. The result (or output) color value is noted Cout.
Summary
Enum values | |
---|---|
PorterDuff.Mode |
ADD
|
PorterDuff.Mode |
CLEAR
|
PorterDuff.Mode |
DARKEN
|
PorterDuff.Mode |
DST
|
PorterDuff.Mode |
DST_ATOP
|
PorterDuff.Mode |
DST_IN
|
PorterDuff.Mode |
DST_OUT
|
PorterDuff.Mode |
DST_OVER
|
PorterDuff.Mode |
LIGHTEN
|
PorterDuff.Mode |
MULTIPLY
|
PorterDuff.Mode |
OVERLAY
|
PorterDuff.Mode |
SCREEN
|
PorterDuff.Mode |
SRC
|
PorterDuff.Mode |
SRC_ATOP
|
PorterDuff.Mode |
SRC_IN
|
PorterDuff.Mode |
SRC_OUT
|
PorterDuff.Mode |
SRC_OVER
|
PorterDuff.Mode |
XOR
|
Public methods | |
---|---|
static
PorterDuff.Mode
|
valueOf(String name)
|
static
final
Mode[]
|
values()
|
Inherited methods | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||
| |||||||||||||||||||||||
|
Enum values
ADD
public static final PorterDuff.Mode ADD
αout=max(0,min(αsrc+αdst,1))
Cout=max(0,min(Csrc+Cdst,1))
CLEAR
public static final PorterDuff.Mode CLEAR
αout=0
Cout=0
DARKEN
public static final PorterDuff.Mode DARKEN
αout=αsrc+αdst−αsrc∗αdst
Cout=(1−αdst)∗Csrc+(1−αsrc)∗Cdst+min(Csrc,Cdst)
DST
public static final PorterDuff.Mode DST
αout=αdst
Cout=Cdst
DST_ATOP
public static final PorterDuff.Mode DST_ATOP
αout=αsrc
Cout=αsrc∗Cdst+(1−αdst)∗Csrc
DST_IN
public static final PorterDuff.Mode DST_IN
αout=αsrc∗αdst
Cout=Cdst∗αsrc
DST_OUT
public static final PorterDuff.Mode DST_OUT
αout=(1−αsrc)∗αdst
Cout=(1−αsrc)∗Cdst
DST_OVER
public static final PorterDuff.Mode DST_OVER
αout=αdst+(1−αdst)∗αsrc
Cout=Cdst+(1−αdst)∗Csrc
LIGHTEN
public static final PorterDuff.Mode LIGHTEN
αout=αsrc+αdst−αsrc∗αdst
Cout=(1−αdst)∗Csrc+(1−αsrc)∗Cdst+max(Csrc,Cdst)
MULTIPLY
public static final PorterDuff.Mode MULTIPLY
αout=αsrc∗αdst
Cout=Csrc∗Cdst
OVERLAY
public static final PorterDuff.Mode OVERLAY
αout=αsrc+αdst−αsrc∗αdst
Cout={2∗Csrc∗Cdst2∗Cdst<αdstαsrc∗αdst−2(αdst−Csrc)(αsrc−Cdst)otherwise
SCREEN
public static final PorterDuff.Mode SCREEN
αout=αsrc+αdst−αsrc∗αdst
Cout=Csrc+Cdst−Csrc∗Cdst
SRC
public static final PorterDuff.Mode SRC
αout=αsrc
Cout=Csrc
SRC_ATOP
public static final PorterDuff.Mode SRC_ATOP
αout=αdst
Cout=αdst∗Csrc+(1−αsrc)∗Cdst
SRC_IN
public static final PorterDuff.Mode SRC_IN
αout=αsrc∗αdst
Cout=Csrc∗αdst
SRC_OUT
public static final PorterDuff.Mode SRC_OUT
αout=(1−αdst)∗αsrc
Cout=(1−αdst)∗Csrc
SRC_OVER
public static final PorterDuff.Mode SRC_OVER
αout=αsrc+(1−αsrc)∗αdst
Cout=Csrc+(1−αsrc)∗Cdst
XOR
public static final PorterDuff.Mode XOR
αout=(1−αdst)∗αsrc+(1−αsrc)∗αdst
Cout=(1−αdst)∗Csrc+(1−αsrc)∗Cdst
Public methods
valueOf
public static PorterDuff.Mode valueOf (String name)
Parameters | |
---|---|
name |
String |
Returns | |
---|---|
PorterDuff.Mode |