private static byte[] get_byte_data(BufferedImage image)
{
//WritableRaster raster = image.getRaster();
DataBufferByte buffer = (DataBufferByte)image.getRaster().getDataBuffer();
return buffer.getData();
}
我在执行上面的代码时得到了声明的类强制转换异常。我需要返回 byte[] 数组。即缓冲图像的字节数。
最佳答案
栅格数据不一定是字节。
如果 (image.getRaster().getDataTypeSize() == 1)
,那么您可以对所有银行和所有银行使用 getElem(int bank, int i)
元素,并将结果存储在所需的数组中。我看不到任何更直接的东西。
关于java.awt.image.DataBufferInt 无法转换为 java.awt.image.DataBufferByte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12662415/