// 这是去处图象中某一种颜色的例子 public class UTImageFilter extends RGBImageFilter { private Color paintColor; public UTImageFilter(Color c) {
canFilterIndexColorModel = true; paintColor = c; } public int filterRGB(int x, int y, int rgb) { DirectColorModel cm = (DirectColorModel)ColorModel.getRGBdefault(); int alpha = cm.getAlpha(rgb); int red = paintColor.getRed(); int green = paintColor.getGreen(); int blue = paintColor.getBlue(); int mycolor = alpha << 24 | red << 16 | green << 8 | blue; if(rgb == mycolor) return 0; else return rgb; } }// call method public static Image getPaintImage(Image oldImg, Color c) { UTImageFilter imgFilter = new UTImageFilter(c); Image newImg = null; newImg = Toolkit.getDefaultToolkit().createImage( new FilteredImageSource(oldImg.getSource(), imgFilter)); return newImg; }
public class UTImageFilter extends RGBImageFilter
{
private Color paintColor; public UTImageFilter(Color c)
{
canFilterIndexColorModel = true; paintColor = c;
} public int filterRGB(int x, int y, int rgb)
{
DirectColorModel cm = (DirectColorModel)ColorModel.getRGBdefault(); int alpha = cm.getAlpha(rgb); int red = paintColor.getRed(); int green = paintColor.getGreen(); int blue = paintColor.getBlue();
int mycolor = alpha << 24 | red << 16 | green << 8 | blue;
if(rgb == mycolor)
return 0;
else
return rgb;
}
}// call method
public static Image getPaintImage(Image oldImg, Color c)
{ UTImageFilter imgFilter = new UTImageFilter(c); Image newImg = null; newImg =
Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(oldImg.getSource(), imgFilter)); return newImg;
}