Creating a 16 or 32-bit image from an array of bytes

Given the width, height, depth and array of bytes of the image, I need to create a SWT image object. I currently have no problem providing data for 8-bit images.

int imageWidth;
int imageHeight;
int depth;
byte[] imageBytes;
//calculate the values

imageData = new ImageData( imageWidth, imageHeight, depth, new PaletteData(255,255,255), 1, imageBytes);
new Image( display, imageData );

The problem is that for 16-bit images, the color is off a bit. What should be the black pixels are actually gray.

For 32-bit images, only a few black pixels are displayed, and the rest of the image is white.

Any ideas?

Thank.

Edit: the imageBytes array is read from a proprietary image file that I could not get for the specification (and therefore I'm not quite sure about the format).

32- . , 32- RGBAX. 24- , , 16- ( ).

imageBytes ( * * (/8)), .

, . , , , , , .

+3
2

, , , . , Java byte datatype 8 > , , 16- , Java bytes . , 32- Java bytes 4.

, 32- , [0 0 0 255] - ( , ). , .

:

  • imageBytes?
  • ? , width*height*depth/8, depth .

, :

  • SWT, , ImageData
  • bytes imageBytes. , 32- [0 0 0 255] [255 0 0 0 ].
0

, () (b) , , , - (, /). 50% .

op ( 16 ...) .

, : finalByte = originalByte & 0x7f;

, (RLE) varint, / , , , .

0

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


All Articles