Class BlendComposite

java.lang.Object
org.jdesktop.swingx.graphics.BlendComposite
All Implemented Interfaces:
Composite

public final class BlendComposite extends Object implements 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:

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:

Author:
Romain Guy romain.guy@mac.com, Karl Schaefer (support and additional modes)
See Also:
  • Field Details

    • Average

      public static final BlendComposite Average
      factory for BlendingMode.AVERAGE
    • Multiply

      public static final BlendComposite Multiply
      factory for BlendingMode.MULTIPLY
    • Screen

      public static final BlendComposite Screen
      factory for BlendingMode.SCREEN
    • Darken

      public static final BlendComposite Darken
      factory for BlendingMode.DARKEN
    • Lighten

      public static final BlendComposite Lighten
      factory for BlendingMode.LIGHTEN
    • Overlay

      public static final BlendComposite Overlay
      factory for BlendingMode.OVERLAY
    • HardLight

      public static final BlendComposite HardLight
      factory for BlendingMode.HARD_LIGHT
    • SoftLight

      public static final BlendComposite SoftLight
      factory for BlendingMode.SOFT_LIGHT
    • VividLight

      public static final BlendComposite VividLight
      factory for BlendingMode.VIVID_LIGHT
    • LinearLight

      public static final BlendComposite LinearLight
      factory for BlendingMode.LINEAR_LIGHT
    • PinLight

      public static final BlendComposite PinLight
      factory for BlendingMode.PIN_LIGHT
    • HardMix

      public static final BlendComposite HardMix
      factory for BlendingMode.HARD_MIX
    • Difference

      public static final BlendComposite Difference
      factory for BlendingMode.DIFFERENCE
    • Negation

      public static final BlendComposite Negation
      factory for BlendingMode.NEGATION
    • Exclusion

      public static final BlendComposite Exclusion
      factory for BlendingMode.EXCLUSION
    • ColorDodge

      public static final BlendComposite ColorDodge
      factory for BlendingMode.COLOR_DODGE
    • InverseColorDodge

      public static final BlendComposite InverseColorDodge
      factory for BlendingMode.INVERSE_COLOR_DODGE
    • SoftDodge

      public static final BlendComposite SoftDodge
      factory for BlendingMode.SOFT_DODGE
    • ColorBurn

      public static final BlendComposite ColorBurn
      factory for BlendingMode.COLOR_BURN
    • InverseColorBurn

      public static final BlendComposite InverseColorBurn
      factory for BlendingMode.INVERSE_COLOR_BURN
    • SoftBurn

      public static final BlendComposite SoftBurn
      factory for BlendingMode.SOFT_BURN
    • Reflect

      public static final BlendComposite Reflect
      factory for BlendingMode.REFLECT
    • Glow

      public static final BlendComposite Glow
      factory for BlendingMode.GLOW
    • Freeze

      public static final BlendComposite Freeze
      factory for BlendingMode.FREEZE
    • Heat

      public static final BlendComposite Heat
      factory for BlendingMode.HEAT
    • Add

      public static final BlendComposite Add
      factory for BlendingMode.ADD
    • Subtract

      public static final BlendComposite Subtract
      factory for BlendingMode.SUBTRACT
    • Stamp

      public static final BlendComposite Stamp
      factory for BlendingMode.STAMP
    • Red

      public static final BlendComposite Red
      factory for BlendingMode.RED
    • Green

      public static final BlendComposite Green
      factory for BlendingMode.GREEN
    • Blue

      public static final BlendComposite Blue
      factory for BlendingMode.BLUE
    • Hue

      public static final BlendComposite Hue
      factory for BlendingMode.HUE
    • Saturation

      public static final BlendComposite Saturation
      factory for BlendingMode.SATURATION
    • Color

      public static final BlendComposite Color
      factory for BlendingMode.COLOR
    • Luminosity

      public static final BlendComposite Luminosity
      factory for BlendingMode.LUMINOSITY
  • Method Details

    • getInstance

      public static BlendComposite getInstance(BlendComposite.BlendingMode mode)

      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

      public static BlendComposite getInstance(BlendComposite.BlendingMode mode, float alpha)

      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 rule
      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 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

      public BlendComposite derive(float alpha)

      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

      public BlendComposite.BlendingMode getMode()

      Returns the blending mode of this composite.

      Returns:
      the blending mode used by this object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • createContext

      public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints)
      Specified by:
      createContext in interface Composite