I'm working for a swing project and I have to display the same image multiple times, by changing pixels color every time.
For example : the first image must be displayed in blue and the second one must be displayed in orange, but the problem is that when the second one is displayed, it changes the color of the first one in orange, too. How can I display every image with its color ?
Thank you.
private void drawPixel(int index,String name) throws IOException {
File input = new File("map-pointer-clipart-3.png");
BufferedImage imagePointer = ImageIO.read(input);
Graphics g = this.imagePoints.getGraphics();
changeColorPixelLabel(imagePointer,labelClassesCount-1);
int x = (index % this.width);
int y = (index / this.width);
g.drawImage(imagePointer,x-20, y-31,100,100, null);
repaint();
}
private void changeColorPixelLabel(BufferedImage img, int index) {
for(int i=0; i<img.getWidth(); i++) {
for(int j=0; j<img.getHeight(); j++) {
Color c = labelConstraintColor.get(index);
if(img.getRGB(i, j) == new Color(255,255,255).getRGB()) {
img.setRGB(i, j, c.getRGB());
}
}
}
}