【发布时间】:2015-04-30 11:16:46
【问题描述】:
请不要不喜欢这个“通用问题”,因为它确实是个问题。我还搜索了其他问题,问题总是人们想要实例化接口。那不是我的情况。
ColorModel 类不是接口,它有一个采用int 的构造函数。为什么会出现“无法实例化类型 ColorModel”的错误?
代码如下:
package test;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class BufferedImageGetRGB {
public static void main(String...args) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("C:\\Users\\xxxxx\\Desktop\\testbinary.png"));
} catch (IOException e) {}
for (int y=0; y<img.getHeight(); ++y) {
for (int x=0; x<img.getWidth(); ++x) {
System.out.println(img.getRGB(y, x));
ColorModel cm = new ColorModel(img.getRGB(y, x));
}
}
}
}
【问题讨论】:
标签: java awt bufferedimage