Hello all, I’ve been working on this problem off and on for the past few months and haven’t been able to figure it out. Basically, I am trying to create a bufferedimage out of a byte[][] array and a IndexColorModel palette, and have no clue how to go about doing it. Currently, this is the code I have, but it doesn’t work whatsoever.
IndexColorModel palette = new IndexColorModel(numBits, size+1, reds, grns, blus, indexOfTransPixel);
byte[][] data = ...;
DataBufferByte imageData = new DataBufferByte(data, data.length);
SampleModel model = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
imageData.getBankData().length,
imageData.getBankData()[0].length,
1, imageData.getBankData().length, new int[] {255});
WritableRaster raster = Raster.createWritableRaster(
model,
imageData,
new Point(0,0));
BufferedImage renderedBi = new BufferedImage(palette,raster,true, new Hashtable());
Any help would be greatly appreciated! (The reason I’m trying to do this is to save space, there are multiple factions each with a lot of animated sprites that have different palettes)