I want to filter my BufferedImage
in java.
Currently, I have this piece of code:
private void changeRGB(BufferedImage image, int colour) {
int width = image.getWidth();
int height = image.getHeight();
int newColor = 0;
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
Color color = new Color(image.getRGB(x,y));
int red = color.getRed();
int green = color.getGreen();
int blue = color.getBlue();
if (colour == 1) {
newColor = new Color(red, 0, 0).getRGB();
} else if (colour == 2) {
newColor = new Color(0, green, 0).getRGB();
} else if (colour == 3) {
newColor = new Color(0, 0, blue).getRGB();
}
image.setRGB(x, y, newColor);
}
}
icon = new ImageIcon(image);
this.lblFilteredImage.setIcon(icon);
}
and if I press e.g. the red, green or blue button I do it this way:
choice = 2; changeRGB(img, choice);
This code works one time and if I press one of these buttons the 2nd time it doesn't work anymore