Usually we do to extract a color that is exactly equal to or almost equal to the color, takes a threshold.
Here is your code with a few changes:
public static Image makeColorTransparent(BufferedImage im, final Color color, float threshold) {
ImageFilter filter = new RGBImageFilter() {
public float markerAlpha = color.getRGB() | 0xFF000000;
public final int filterRGB(int x, int y, int rgb) {
int currentAlpha = rgb | 0xFF000000;
float diff = Math.abs((currentAlpha - markerAlpha) / markerAlpha);
if (diff <= threshold) {
return 0x00FFFFFF & rgb;
} else {
return rgb;
}
}
};
ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(ip);
}
makeColorTransparent(image, color, 0.05f);
. ( ) . , algo .
, , . . , . 0.05f , , ( Photoshop ).
