This week's book giveaway is in the Testing forum. We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line! See this thread for details.
Creating an image from a byte array and a color palette
posted 6 years ago
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?