Extend RGBImageFilter to create AlphaFilter class : RGBImageFilter « 2D Graphics « Java Tutorial






import java.awt.image.RGBImageFilter;

class AlphaFilter extends RGBImageFilter {
  int alphaLevel;

  public AlphaFilter(int alpha) {
    alphaLevel = alpha;
    canFilterIndexColorModel = true;
  }

  public int filterRGB(int x, int y, int rgb) {
    int alpha = (rgb >> 24) & 0xff;
    alpha = (alpha * alphaLevel) / 255;
    return ((rgb & 0x00ffffff) | (alpha << 24));
  }
}








16.35.RGBImageFilter
16.35.1.Extend RGBImageFilter ColorFilter class
16.35.2.Extend RGBImageFilter to create AlphaFilter class