Create a filter that can modify any of the RGB pixel values in an image.
import java.awt.Image; import java.awt.Toolkit; import java.awt.image.FilteredImageSource; import java.awt.image.ImageFilter; import java.awt.image.RGBImageFilter; import javax.swing.ImageIcon; class GetRedFilter extends RGBImageFilter { public GetRedFilter() { canFilterIndexColorModel = true; } public int filterRGB(int x, int y, int rgb) { if (x == -1) { } return rgb & 0xffff0000; } } public class Main { public static void main(String[] argv) throws Exception { Image image = new ImageIcon("image.gif").getImage(); ImageFilter filter = new GetRedFilter(); FilteredImageSource filteredSrc = new FilteredImageSource(image.getSource(), filter); image = Toolkit.getDefaultToolkit().createImage(filteredSrc); } }