开发者

16 bit (565) image read

开发者 https://www.devze.com 2023-02-26 22:55 出处:网络
I\'m reading an image byte array now the image is 16 bit (r: 5, g: 6, b:开发者_开发知识库 5) and I would like to read it to BufferedImage.

I'm reading an image byte array now the image is 16 bit (r: 5, g: 6, b:开发者_开发知识库 5) and I would like to read it to BufferedImage.

I have tried something like:


int[] nBits = {5, 6, 5};
int[] bOffs = {0, 0, 0};
ColorModel colorModel = new ComponentColorModel(
        cs, nBits, false, false,
        Transparency.OPAQUE,
        DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(
        new DataBufferByte(screenBuffer,screenBuffer.length),
        foundWidth, foundHight,
        foundWidth * 2, 2,bOffs, null);

BufferedImage imgReconstructed = new BufferedImage(
        colorModel,raster,false,null);


My issue is with the bandOffsets, how should I set it for 16 bit image. Is it the right way? Thanks, Guy


The createInterleavedRaster method would be used to create an image with a sample model where each data element contained color information for a single band (i.e. red, green, or blue). If you want an image where each 16-bit data element contains all 3 color bands, you want to use one of the createPackedRaster methods instead.

The only sixteen bit data type supported by these models is unsigned short, so you will want to pass a DataBufferUShort instance.

I do not have access to a compiler at the moment to put together a working code sample for you, but the SinglePixelPackedSampleModel API documentation will help explain the scanlineStride and band mask parameters a little bit. If needed, I will update this response later with more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消