我想编写一个程序,帮助我检查图像的任何像素是否存在某种颜色。扫描一个图像的某种颜色存在
这是我到目前为止有:
public static void main(String args[]) throws IOException {
try {
//read image file
File file1 = new File("./Scan.png");
BufferedImage image1 = ImageIO.read(file1);
//write file
FileWriter fstream = new FileWriter("log1.txt");
BufferedWriter out = new BufferedWriter(fstream);
for (int y = 0; y < image1.getHeight(); y++) {
for (int x = 0; x < image1.getWidth(); x++) {
int c = image1.getRGB(x,y);
Color color = new Color(c);
if (color.getRed() < 50 && color.getGreen() > 225 && color.getBlue() > 43) {
out.write("Specified Pixel found at=" + x + "," + y);
out.newLine();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
我似乎无法得到它的运行,所以我很想得到关于如何做到这一点的正确方法的提示。
具体是什么,你的“我不能让它跑”呢?它是否构建?如果它构建,它会做什么? – nicomp
你得到的错误 –
“BufferedImage类型中的方法getRGB(int,int)不适用于参数()” – marcelxvi