John
John

Reputation: 317

Error when trying to convert BufferedImage into int array

I am trying to convert my BufferedImage into a integer array, but i am getting the following error: "java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt"

Here's my bit of code:

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();
  }
}

Upvotes: 0

Views: 2291

Answers (1)

Eugene Retunsky
Eugene Retunsky

Reputation: 13139

Try this:

byte[] imgarray = ((DataBufferByte)img.getRaster().getDataBuffer()).getData();

Upvotes: 3

Related Questions