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.BLUEandBlendComposite.BlendingMode.GREENhave been swapped.
- Author:
- Romain Guy romain.guy@mac.com, Karl Schaefer (support and additional modes)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA blending mode defines the compositing rule of aBlendComposite. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BlendCompositefactory for BlendingMode.ADDstatic final BlendCompositefactory for BlendingMode.AVERAGEstatic final BlendCompositefactory for BlendingMode.BLUEstatic final BlendCompositefactory for BlendingMode.COLORstatic final BlendCompositefactory for BlendingMode.COLOR_BURNstatic final BlendCompositefactory for BlendingMode.COLOR_DODGEstatic final BlendCompositefactory for BlendingMode.DARKENstatic final BlendCompositefactory for BlendingMode.DIFFERENCEstatic final BlendCompositefactory for BlendingMode.EXCLUSIONstatic final BlendCompositefactory for BlendingMode.FREEZEstatic final BlendCompositefactory for BlendingMode.GLOWstatic final BlendCompositefactory for BlendingMode.GREENstatic final BlendCompositefactory for BlendingMode.HARD_LIGHTstatic final BlendCompositefactory for BlendingMode.HARD_MIXstatic final BlendCompositefactory for BlendingMode.HEATstatic final BlendCompositefactory for BlendingMode.HUEstatic final BlendCompositefactory for BlendingMode.INVERSE_COLOR_BURNstatic final BlendCompositefactory for BlendingMode.INVERSE_COLOR_DODGEstatic final BlendCompositefactory for BlendingMode.LIGHTENstatic final BlendCompositefactory for BlendingMode.LINEAR_LIGHTstatic final BlendCompositefactory for BlendingMode.LUMINOSITYstatic final BlendCompositefactory for BlendingMode.MULTIPLYstatic final BlendCompositefactory for BlendingMode.NEGATIONstatic final BlendCompositefactory for BlendingMode.OVERLAYstatic final BlendCompositefactory for BlendingMode.PIN_LIGHTstatic final BlendCompositefactory for BlendingMode.REDstatic final BlendCompositefactory for BlendingMode.REFLECTstatic final BlendCompositefactory for BlendingMode.SATURATIONstatic final BlendCompositefactory for BlendingMode.SCREENstatic final BlendCompositefactory for BlendingMode.SOFT_BURNstatic final BlendCompositefactory for BlendingMode.SOFT_DODGEstatic final BlendCompositefactory for BlendingMode.SOFT_LIGHTstatic final BlendCompositefactory for BlendingMode.STAMPstatic final BlendCompositefactory for BlendingMode.SUBTRACTstatic final BlendCompositefactory for BlendingMode.VIVID_LIGHT -
Method Summary
Modifier and TypeMethodDescriptioncreateContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) derive(float alpha) Returns aBlendCompositeobject that uses the specified opacity, or alpha, and this object's blending mode.Returns aBlendCompositeobject that uses the specified blending mode and this object's alpha value.booleanfloatgetAlpha()Returns the opacity of this composite.static BlendCompositeCreates a new composite based on the blending mode passed as a parameter.static BlendCompositegetInstance(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.inthashCode()
-
Field Details
-
Average
factory for BlendingMode.AVERAGE -
Multiply
factory for BlendingMode.MULTIPLY -
Screen
factory for BlendingMode.SCREEN -
Darken
factory for BlendingMode.DARKEN -
Lighten
factory for BlendingMode.LIGHTEN -
Overlay
factory for BlendingMode.OVERLAY -
HardLight
factory for BlendingMode.HARD_LIGHT -
SoftLight
factory for BlendingMode.SOFT_LIGHT -
VividLight
factory for BlendingMode.VIVID_LIGHT -
LinearLight
factory for BlendingMode.LINEAR_LIGHT -
PinLight
factory for BlendingMode.PIN_LIGHT -
HardMix
factory for BlendingMode.HARD_MIX -
Difference
factory for BlendingMode.DIFFERENCE -
Negation
factory for BlendingMode.NEGATION -
Exclusion
factory for BlendingMode.EXCLUSION -
ColorDodge
factory for BlendingMode.COLOR_DODGE -
InverseColorDodge
factory for BlendingMode.INVERSE_COLOR_DODGE -
SoftDodge
factory for BlendingMode.SOFT_DODGE -
ColorBurn
factory for BlendingMode.COLOR_BURN -
InverseColorBurn
factory for BlendingMode.INVERSE_COLOR_BURN -
SoftBurn
factory for BlendingMode.SOFT_BURN -
Reflect
factory for BlendingMode.REFLECT -
Glow
factory for BlendingMode.GLOW -
Freeze
factory for BlendingMode.FREEZE -
Heat
factory for BlendingMode.HEAT -
Add
factory for BlendingMode.ADD -
Subtract
factory for BlendingMode.SUBTRACT -
Stamp
factory for BlendingMode.STAMP -
Red
factory for BlendingMode.RED -
Green
factory for BlendingMode.GREEN -
Blue
factory for BlendingMode.BLUE -
Hue
factory for BlendingMode.HUE -
Saturation
factory for BlendingMode.SATURATION -
Color
factory for BlendingMode.COLOR -
Luminosity
factory for BlendingMode.LUMINOSITY
-
-
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
BlendCompositebased 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.alphamust be a floating point between 0.0 and 1.0.- Returns:
- a new
BlendCompositebased 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
BlendCompositeobject 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
BlendCompositeobject derived from this object, that uses the specified blending mode
-
derive
Returns a
BlendCompositeobject 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.alphamust be a floating point between 0.0 and 1.0.- Returns:
- a
BlendCompositeobject 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
-
createContext
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) - Specified by:
createContextin interfaceComposite
-