Hi,
Ok, ran into a new problem.
When using ImageIO to load into a BufferedImage directly, the above works fine.
I can’t use this though, since I’m writing an applet. Have to use getImage() instead.
So, I created a BufferedImage with type TYPE_BYTE_INDEXED, and gave it a new IndexColorModel object. Then I drew the previously loaded Image onto it.
So far so good. However, using the above code to grab the palette index from a pixel just gives nonsensical values.
Here’s the code:
//create a new indexcolormodel
byte[] t = new byte[16];
IndexColorModel icm = new IndexColorModel(4,16,t,t,t);
//draw the loaded image onto a BufferedImage
tempImage = new BufferedImage(w,h,BufferedImage.TYPE_BYTE_INDEXED,icm);
tempImage.createGraphics().drawImage(tempImage2,0,0,null);
//grab a pixel
int [] pixel = new int[1];
tempImage.getData().getPixel(0,0,pixel);
System.out.println(pixel[0]);
On a bitmap where the first three horizontal pixels have the values 1,2,1 this code will return 15, 15, 15.
Any ideas?