I have the following java code
final byte[] pixels;
DataBuffer rasterData = image.getRaster().getDataBuffer();
DataBufferByte rasterByteData = (DataBufferByte)rasterData;
pixels = rasterByteData.getData();
Where image is a object of type BufferedImage
, I wish to convert the Image
to a DataBufferByte
object but my cast throws the following error.
java.lang.ClassCastException: java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte
I am trying to use the code from this post Java - get pixel array from image
Any ideas how to cast or why I cannot cast from DataBuffer
to DataBufferByte
?
EDIT: Changed Image
to BufferedImage