I\'m trying to write 16 bit grayscale imagedata to a png using BufferedImage.TYPE_USHORT_GRAY. Normally I write to an image like so:
BufferedImage image = ne
As pst already commented below my question:
Try using the Raster directly?
Accessing the Raster directly solved the problem.
You probably need to widen the signed 16bit shorts to ints and remove the sign:
int ushort = (int)(shortData[x][y]) & 0xFFFF;
From BufferedImage
you can read
public static final int TYPE_USHORT_GRAY
Represents an unsigned short grayscale image, non-indexed). This image has a ComponentColorModel with a CS_GRAY ColorSpace.
So try instantiating your own ColorSpace
with the CS_GRAY
type (ColorSpace.getInstance(ColorSpace.CS_GRAY)
should do it I suppose). This object has a method called fromRGB
which you should be able to use...