获取索引图像的数据(调色板索引)

时间:2012-09-01 09:54:21

标签: java image palette

如何访问索引图像(png8或gif)的图像数据(调色板索引数组)?

示例:

  • 图像调色板:{0xFF0000,0x00FF00,0x0000FF}
  • 图像数据:{0,1,1,0,1,2,2,2,0,1,0,2,0,1,1,0}

我需要的是:

ArrayList<Integer> getImageData(File image) {
  /* ??? */
}

1 个答案:

答案 0 :(得分:0)

以下代码会将图片数据读入imageData int数组。

  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);