我正在尝试将BufferedImage
转换为整数数组,但是我收到以下错误:“java.awt.image.DataBufferByte
无法转换为java.awt.image.DataBufferInt
”
这是我的一些代码:
public class Test {
public static void main (String [] args) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("G.bmp"));
} catch (IOException e) { }
int[] imgarray = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
}
}
答案 0 :(得分:3)
试试这个:
byte[] imgarray = ((DataBufferByte)img.getRaster().getDataBuffer()).getData();