AlphaComposite

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.awt
Class AlphaComposite

    java.lang.Object
      java.awt.AlphaComposite

All Implemented Interfaces:
  Composite

    public final class AlphaComposite

extends Object
implements Composite

This `AlphaComposite` class implements the basic alpha compositing rules for combining source and destination pixels to achieve blending and transparency effects with graphics and images. The rules implemented by this class are the set of Porter-Duff rules described in T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84, 253-259.

If any input does not have an alpha channel, an alpha value of 1.0, which is completely opaque, is assumed for all pixels. A constant alpha value can also be specified to be multiplied with the alpha value of the source pixels.

The following abbreviations are used in the description of the rules:

- Cs = one of the color components of the source pixel.
- Cd = one of the color components of the destination pixel.
- As = alpha component of the source pixel.
- Ad = alpha component of the destination pixel.
- Fs = fraction of the source pixel that contributes to the output.
- Fd = fraction of the input destination pixel that contributes to the output.

The color and alpha components produced by the compositing operation are calculated as follows:

            Cd = Cs*Fs + Cd*Fd
            Ad = As*Fs + Ad*Fd

where Fs and Fd are specified by each rule. The above equations assume that both source and destination pixels have the color components premultiplied by the alpha component. Similarly, the equations expressed in the definitions of compositing rules below assume premultiplied alpha.

The alpha resulting from the compositing operation is stored in the destination if the destination has an alpha channel. Otherwise, the resulting color is divided by the resulting alpha before being stored in the destination and the alpha is discarded. If the alpha value is 0.0, the color values are set to 0.0.

If either source or destination pixels have color components not premultiplied by the alpha component, appropriate conversions are performed before and after the compositing operation.

#### Restrictions

Implementations of alpha compositing in this Profile exhibit certain restrictions, specifically:

- An implementation may approximate the result of the `SRC_OVER` rule in the case that `0.0 < As < 1.0`. See:
  - `SRC_OVER`

For more information, see Profile-specific properties.

Version:
  10 Feb 1997
See Also:
  ``

Field Summary
`static AlphaComposite` | `Clear` `AlphaComposite` object that implements the opaque CLEAR rule with an alpha of 1.0f.
`static int` | `CLEAR` Porter-Duff Clear rule.
`static AlphaComposite` | `Src` `AlphaComposite` object that implements the opaque SRC rule with an alpha of 1.0f.
`static int` | `SRC` Porter-Duff Source rule.
`static int` | `SRC_OVER` Porter-Duff Source Over Destination rule.
`static AlphaComposite` | `SrcOver` `AlphaComposite` object that implements the opaque SRC_OVER rule with an alpha of 1.0f.

Method Summary
`boolean` | `equals(Object obj)` Determines whether the specified object is equal to this `AlphaComposite`.
`float` | `getAlpha()` Returns the alpha value of this `AlphaComposite`.
`static AlphaComposite` | `getInstance(int rule)` Creates an `AlphaComposite` object with the specified rule.
`static AlphaComposite` | `getInstance(int rule, float alpha)` Creates an `AlphaComposite` object with the specified rule and the constant alpha to multiply with the alpha of the source.
`int` | `getRule()` Returns the compositing rule of this `AlphaComposite`.
`int` | `hashCode()` Returns the hashcode for this composite.

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CLEAR

    public static final int CLEAR

  Porter-Duff Clear rule. Both the color and the alpha of the destination are cleared. Neither the source nor the destination is used as input.

  Fs = 0 and Fd = 0, thus:

              Cd = 0
              Ad = 0

  See Also:
    Constant Field Values

### SRC

    public static final int SRC

  Porter-Duff Source rule. The source is copied to the destination. The destination is not used as input.

  Fs = 1 and Fd = 0, thus:

              Cd = Cs
              Ad = As

  See Also:
    Constant Field Values

### SRC_OVER

    public static final int SRC_OVER

  Porter-Duff Source Over Destination rule. The source is composited over the destination.

  Fs = 1 and Fd = (1-As), thus:

              Cd = Cs + Cd*(1-As)
              Ad = As + Ad*(1-As)

  Note: This operation is subject to restriction in this Profile.

  See Also:
    Constant Field Values

### Clear

    public static final AlphaComposite Clear

  `AlphaComposite` object that implements the opaque CLEAR rule with an alpha of 1.0f.

  See Also:
    `CLEAR`

### Src

    public static final AlphaComposite Src

  `AlphaComposite` object that implements the opaque SRC rule with an alpha of 1.0f.

  See Also:
    `SRC`

### SrcOver

    public static final AlphaComposite SrcOver

  `AlphaComposite` object that implements the opaque SRC_OVER rule with an alpha of 1.0f.

  See Also:
    `SRC_OVER`

Method Detail

### getInstance

    public static AlphaComposite getInstance(int rule)

  Creates an `AlphaComposite` object with the specified rule.

  Parameters:
    `rule` - the compositing rule
  Throws:
    `IllegalArgumentException` - if `rule` is not one of the following: `CLEAR`, `SRC`, or `SRC_OVER`

### getInstance

    public static AlphaComposite getInstance(int rule,
                                             float alpha)

  Creates an `AlphaComposite` object with the specified rule and the constant alpha to multiply with the alpha of the source. The source is multiplied with the specified alpha before being composited with the destination.

  Parameters:
    `rule` - the compositing rule
    `alpha` - the constant alpha to be multiplied with the alpha of the source. `alpha` must be a floating point number in the inclusive range [0.0, 1.0].
  Throws:
    `IllegalArgumentException` - if `alpha` is less than 0.0 or greater than 1.0, or if `rule` is not one of the following: `CLEAR`, `SRC`, or `SRC_OVER`

### getAlpha

    public float getAlpha()

  Returns the alpha value of this `AlphaComposite`. If this `AlphaComposite` does not have an alpha value, 1.0 is returned.

  Returns:
    the alpha value of this `AlphaComposite`.

### getRule

    public int getRule()

  Returns the compositing rule of this `AlphaComposite`.

  Returns:
    the compositing rule of this `AlphaComposite`.

### hashCode

    public int hashCode()

  Returns the hashcode for this composite.

  Overrides:
    `hashCode` in class `Object`
  Returns:
    a hash code for this composite.
  See Also:
    `Object.equals(java.lang.Object)`, `Hashtable`

### equals

    public boolean equals(Object obj)

  Determines whether the specified object is equal to this `AlphaComposite`.

  The result is `true` if and only if the argument is not `null` and is an `AlphaComposite` object that has the same compositing rule and alpha value as this object.

  Overrides:
    `equals` in class `Object`
  Parameters:
    `obj` - the `Object` to test for equality
  Returns:
    `true` if `obj` equals this `AlphaComposite`; `false` otherwise.
  See Also:
    `Object.hashCode()`, `Hashtable`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD