How can I access the image data (array of palette indices) of an indexed image (png8 or gif)?
Example:
What I need is:
ArrayList<Integer> getImageData(File image) {
/* ??? */
}
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);