简体   繁体   English

尝试将BufferedImage转换为int数组时出错

[英]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 " 我正在尝试将BufferedImage转换为整数数组,但是出现以下错误:“ java.awt.image.DataBufferByte无法转换为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();
  }
}

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM