Hey guys, I’m using an RGBA image for a terrain mixmap, where each channel corresponds to the opacity of a separate terrain texture (so I can blend multiple textures).
The problem is, if I save any pixel with no alpha, for example. RGBA (255,0,0,0) or (20,60,100,0) or (0,200,30,0) it just saves a blank pixel because the alpha component is zero. How can I fix this?
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); //create image
//loop through and set pixels, which come from a bytebuffer which has perfectly fine data in it
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
int i = (x + (width * y)) * 4;
int r = buffer.get(i) & 0xFF;
int g = buffer.get(i + 1) & 0xFF;
int b = buffer.get(i + 2) & 0xFF;
int a = buffer.get(i + 3) & 0xFF; //if i set this to 255 it 'partially works' but then the alpha channel values can't be used
int c = (a << 24) | (r << 16) | (g << 8) | b;
image.setRGB(x, y, c);
}
}
}
ImageIO.write(image, "PNG", filename); //save image
I could just save/load my bytebuffer to/from a file but i’d rather save them as images.
Thanks,
roland