Mega Code Archive

 
Categories / Java / Advanced Graphics
 

Extend RGBImageFilter to create ColorFilter class

import java.awt.image.RGBImageFilter; class ColorFilter extends RGBImageFilter {   boolean red, green, blue;   public ColorFilter(boolean r, boolean g, boolean b) {     red = r;     green = g;     blue = b;     canFilterIndexColorModel = true;   }   public int filterRGB(int x, int y, int rgb) {     int r = red ? 0 : ((rgb >> 16) & 0xff);     int g = green ? 0 : ((rgb >> 8) & 0xff);     int b = blue ? 0 : ((rgb >> 0) & 0xff);     return (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0);   } }