Im trying to create a 16-bit PNG but cant get it keeps writing just black. Also how can i convert an 8-bit color defined as 255,255,255/r,g,b to a 16-bit color?
BufferedImage bi = new BufferedImage(256, 256,
BufferedImage.TYPE_USHORT_GRAY);
// 65536
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++) {
int mask = 0xf0
int value = 255 & mask; // zero other bits
value >>= 16;
bi.setRGB(i, j, value);
// bi.setRGB(i, j, 65536);
}
File f = new File("gray.png");
try {
ImageIO.write(bi, "png", f);
} catch (IOException e) {
e.printStackTrace();
}
The line value >>= 16 is setting it to zero.
As for converting from 24-bit RGB to 16-bit colours there are usually two ways... RGB565 and RGB555. The digits denote how many bits is given to each colour component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With