Class BlendComposite
- All Implemented Interfaces:
Composite
A blend composite defines the rule according to which a drawing primitive (known as the source) is mixed with existing graphics (know as the destination.)
BlendComposite
is an implementation of the
Composite
interface and must therefore be set as a state on
a Graphics2D
surface.
Please refer to Graphics2D.setComposite(java.awt.Composite)
for more information on how to use this class with a graphics surface.
Blending Modes
This class offers a certain number of blending modes, or compositing rules. These rules are inspired from graphics editing software packages, like Adobe Photoshop or The GIMP.
Given the wide variety of implemented blending modes and the difficulty to describe them with words, please refer to those tools to visually see the result of these blending modes.
Opacity
Each blending mode has an associated opacity, defined as a float value between 0.0 and 1.0. Changing the opacity controls the force with which the compositing operation is applied. For instance, a composite with an opacity of 0.0 will not draw the source onto the destination. With an opacity of 1.0, the source will be fully drawn onto the destination, according to the selected blending mode rule.
The opacity, or alpha value, is used by the composite instance to mutiply the alpha value of each pixel of the source when being composited over the destination.
Creating a Blend Composite
Blend composites can be created in various manners:
- Use one of the pre-defined instance. Example:
BlendComposite.Average
. - Derive one of the pre-defined instances by calling
derive(float)
orderive(BlendingMode)
. Deriving allows you to change either the opacity or the blending mode. Example:BlendComposite.Average.derive(0.5f)
. - Use a factory method:
getInstance(BlendingMode)
orgetInstance(BlendingMode, float)
.
Functionality Change in SwingX 1.6.3
Due to incorrect implementations of various blending modes incompatible changes have occurred. The following will help users alleviate problems during migration:
BlendComposite.BlendingMode.BLUE
andBlendComposite.BlendingMode.GREEN
have been swapped.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
static enum
A blending mode defines the compositing rule of aBlendComposite
.private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BlendComposite
private final float
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
private final BlendComposite.BlendingMode
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
static final BlendComposite
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
private
BlendComposite
(BlendComposite.BlendingMode mode, float alpha) -
Method Summary
Modifier and TypeMethodDescriptioncreateContext
(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) derive
(float alpha) Returns aBlendComposite
object that uses the specified opacity, or alpha, and this object's blending mode.Returns aBlendComposite
object that uses the specified blending mode and this object's alpha value.boolean
float
getAlpha()
Returns the opacity of this composite.static BlendComposite
Creates a new composite based on the blending mode passed as a parameter.static BlendComposite
getInstance
(BlendComposite.BlendingMode mode, float alpha) Creates a new composite based on the blending mode and opacity passed as parameters.getMode()
Returns the blending mode of this composite.int
hashCode()
private static boolean
private static boolean
-
Field Details
-
Average
-
Multiply
-
Screen
-
Darken
-
Lighten
-
Overlay
-
HardLight
-
SoftLight
-
VividLight
-
LinearLight
-
PinLight
-
HardMix
-
Difference
-
Negation
-
Exclusion
-
ColorDodge
-
InverseColorDodge
-
SoftDodge
-
ColorBurn
-
InverseColorBurn
-
SoftBurn
-
Reflect
-
Glow
-
Freeze
-
Heat
-
Add
-
Subtract
-
Stamp
-
Red
-
Green
-
Blue
-
Hue
-
Saturation
-
Color
-
Luminosity
-
alpha
private final float alpha -
mode
-
-
Constructor Details
-
BlendComposite
-
BlendComposite
-
-
Method Details
-
getInstance
Creates a new composite based on the blending mode passed as a parameter. A default opacity of 1.0 is applied.
- Parameters:
mode
- the blending mode defining the compositing rule- Returns:
- a new
BlendComposite
based on the selected blending mode, with an opacity of 1.0
-
getInstance
Creates a new composite based on the blending mode and opacity passed as parameters. The opacity must be a value between 0.0 and 1.0.
- Parameters:
mode
- the blending mode defining the compositing rulealpha
- the constant alpha to be multiplied with the alpha of the source.alpha
must be a floating point between 0.0 and 1.0.- Returns:
- a new
BlendComposite
based on the selected blending mode and opacity - Throws:
IllegalArgumentException
- if the opacity is less than 0.0 or greater than 1.0
-
derive
Returns a
BlendComposite
object that uses the specified blending mode and this object's alpha value. If the newly specified blending mode is the same as this object's, this object is returned.- Parameters:
mode
- the blending mode defining the compositing rule- Returns:
- a
BlendComposite
object derived from this object, that uses the specified blending mode
-
derive
Returns a
BlendComposite
object that uses the specified opacity, or alpha, and this object's blending mode. If the newly specified opacity is the same as this object's, this object is returned.- Parameters:
alpha
- the constant alpha to be multiplied with the alpha of the source.alpha
must be a floating point between 0.0 and 1.0.- Returns:
- a
BlendComposite
object derived from this object, that uses the specified blending mode - Throws:
IllegalArgumentException
- if the opacity is less than 0.0 or greater than 1.0
-
getAlpha
public float getAlpha()Returns the opacity of this composite. If no opacity has been defined, 1.0 is returned.
- Returns:
- the alpha value, or opacity, of this object
-
getMode
Returns the blending mode of this composite.
- Returns:
- the blending mode used by this object
-
hashCode
public int hashCode() -
equals
-
isRgbColorModel
-
isBgrColorModel
-
createContext
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) - Specified by:
createContext
in interfaceComposite
-