• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating an image from a byte array and a color palette

 
Panagiotis Peikidis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the story so far:

I have a binary file that contains an icon and the color palette of that icon.

The icon is 32x32 "pixels". The data for this is 512bytes. Each "pixel" in the icon is actually a 4bit index to the color palette.

The color palette contains 16 colors. The data for this is 32bytes. Each color is 16bits long and is encoded in the following format: "BBBBBGGGGGRRRRRU". 5 bits for blue (B), 5 bits for green (G), 5 bits for red (R) and the last bit is unused (U). As you can see, it is encoded in inverse order, BGR and not RGB.

I have managed to read the image data into an array of 512 bytes.

I have also managed to read each color component into an array of ints and used it to create an IndexColorModel:



What I need to do next is create a Raster from the image data array in order to create a BufferedImage using the ColorModel and the Raster. So far I tried the following with no success:



I am really not familiar with such low level image manipulation (as you can clearly see), so I need some help. Any ideas?

Thank you in advance!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!