Writing 16 bits BufferedImage TYPE_USHORT_GRAY

I am trying to write 16-bit grayscale images to png using BufferedImage.TYPE_USHORT_GRAY. I usually write like this:

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

then

image.setRGB(x,y,Color.getRGB);

to set the pixels, and finally:

ImageIO.write(image, "png", new File(path + ".png"));

for writing to a png image.

But now I have it as an image:

BufferedImage imageGray = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY);

How do I save pixels in this format? Using setRGB () with a 16-bit integer does not work, when I open the saved png file, I see that many stripes are happening.

I tried to keep a simple gradient from 0 to 65535, and then using setRGB () on the image in grayscale and checked the results in Photoshop. I see that the image consists of smaller gradients every 256 lines. I assume that setRGB () or imageIO does not work as I would like.

? ImageIO BufferedImage.TYPE_USHORT_GRAY? 8- ? 16- , , , setRGB() ( x, y)?

+3
3

pst :

?

.

+1

BufferedImage

public static final int TYPE_USHORT_GRAY

, ). ComponentColorModel CS_GRAY ColorSpace.

ColorSpace CS_GRAY (ColorSpace.getInstance(ColorSpace.CS_GRAY) , ). fromRGB, ...

0

You probably need to extend signed 16-bit shorts to int and remove the character:

int ushort = (int)(shortData[x][y]) & 0xFFFF;
0
source

Source: https://habr.com/ru/post/1773472/


All Articles