我使用 imageJ 库来读取 .tiff 图像文件。但是当我试图读取变量 c 中 image1 的像素时,我收到一条错误消息:“不兼容的类型:需要 int,找到 int []。我对 java 很陌生,所以有人可以告诉我如何解决这个问题。否则代码可以与其他图像格式一起正常工作。
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.imageio.ImageIO;
import ij.ImagePlus;
public class GetPixelCoordinates {
//int y, x, tofind, col;
/**
* @param args the command line arguments
* @throws IOException
*/
public static void main(String args[]) throws IOException {
try {
//read image file
ImagePlus img = new ImagePlus("E:\\abc.tiff");
//write file
FileWriter fstream = new FileWriter("E:\\log.txt");
BufferedWriter out = new BufferedWriter(fstream);
//find cyan pixels
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int c = img.getPixel(x,y);
Color color = new Color(c);
if (color.getRed() < 30 && color.getGreen() >= 225 && color.getBlue() >= 225) {
out.write("CyanPixel found at=" + x + "," + y);
out.newLine();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}