2
如何访问索引图像(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) {
/* ??? */
}
如何访问索引图像(png8或gif)的图像数据(调色板索引数组)?获取索引图像的数据(调色板索引)
实施例:
我需要的是:
ArrayList<Integer> getImageData(File image) {
/* ??? */
}
下面的代码将读取的图像数据进imageData
,的阵列值。
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);
谢谢,这正是我正在寻找的。 – Aoshi
顺便说一句:'ArrayList'是错误的。泛型类必须使用引用类型进行输入,并且必须*不能使用原始类型。你必须使用拳击类'整数' - >'ArrayList '是正确的 –
halex
谢谢你,我已经纠正它。 – Aoshi