简体   繁体   中英

16 bit (565) image read

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM