• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Creating an image from a byte array and a color palette

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic