Get the data (palette indices) of an indexed image
Question
How can I access the image data (array of palette indices) of an indexed image (png8 or gif)?
Example:
- Image palette: {0xFF0000, 0x00FF00, 0x0000FF}
- Image data: {0,1,1,0,1,2,2,2,0,1,0,2,0,1,1,0}
What I need is:
ArrayList<Integer> getImageData(File image) {
/* ??? */
}
La solution
The code below will read the image data into imageData
, an array of int
values.
BufferedImage image = ImageIO.read(imageFile);
int width = image.getWidth();
int height = image.getHeight();
int[] imageData = new int[width * height * image.getColorModel().getNumComponents()];
imageData = image.getData().getPixels(0, 0, width, height, imageData);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow