I have tried to make method which changes one color of BufferedImage to be invisible.
I can't find solution myself so I ask for your help.
Here is method made by me:
public static BufferedImage makeWithoutColor(BufferedImage img, Color col)
{
BufferedImage img1 = img;
BufferedImage img2 = new BufferedImage(img1.getWidth(), img1.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img2.createGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(img1, null, 0, 0);
g.dispose();
for(int i = 0; i < img2.getWidth(); i++)
{
for(int j = 0; i < img2.getHeight(); i++)
{
if(img2.getRGB(i, j) == col.getRGB())
{
img2.setRGB(i, j, 0x8F1C1C);
}
}
}
return img2;
}
And here is one from tutorial i read.
public static BufferedImage makeColorTransparent(BufferedImage ref, Color color) {
BufferedImage image = ref;
BufferedImage dimg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = dimg.createGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(image, null, 0, 0);
g.dispose();
for(int i = 0; i < dimg.getHeight(); i++) {
for(int j = 0; j < dimg.getWidth(); j++) {
if(dimg.getRGB(j, i) == color.getRGB()) {
dimg.setRGB(j, i, 0x8F1C1C);
}
}
}
return dimg;
}