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

Java 获取索引图像的数据(调色板索引),java,image,palette,Java,Image,Palette,如何访问索引图像(png8或gif)的图像数据(调色板索引数组) 例如: 图像调色板:{0xFF0000,0x00FF00,0x0000FF} 图像数据:{0,1,1,0,1,2,2,0,1,0,2,0,1,1,0} 我需要的是: ArrayList<Integer> getImageData(File image) { /* ??? */ } ArrayList getImageData(文件图像){ /* ??? */ } 下面的代码将图像数据读入imageData,一

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

例如:

  • 图像调色板:{0xFF0000,0x00FF00,0x0000FF}
  • 图像数据:{0,1,1,0,1,2,2,0,1,0,2,0,1,1,0}
我需要的是:

ArrayList<Integer> getImageData(File image) {
  /* ??? */
}
ArrayList getImageData(文件图像){
/* ??? */
}

下面的代码将图像数据读入
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);

下面的代码将图像数据读入
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);

顺便说一句:
ArrayList
是错误的。泛型类必须使用引用类型进行类型化,而不能使用基元类型。你必须使用boxing类
Integer
->
ArrayList
是正确的谢谢,我已经更正了。顺便说一句:
ArrayList
是错误的。泛型类必须使用引用类型进行类型化,而不能使用基元类型。你必须使用拳击类
Integer
->
ArrayList
正确谢谢,我已经更正了。谢谢,这正是我要找的。谢谢,这正是我要找的。