当我使用 getRGB() 并获得像素颜色红色或绿色或蓝色分量后(没关系,因为它们在灰色图像中相等)并将结果与 MS Paint Eyedropper 结果进行比较,这是不同的事情。
import java.awt.Color;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
public class Separator {
BufferedImage inputImg;
private int _inpupImgWidth;
private int _inpupImgHeight;
public Separator(){
try {
inputImg = ImageIO.read(new File("inputImg.bmp"));
_inpupImgWidth = inputImg.getWidth();
_inpupImgHeight = inputImg.getHeight();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(getGrayPixelData(60, 44));
try {
ImageIO.write(inputImg, "BMP", new File("outputImg.bmp"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void getGrayPixelData(int x, int y){
Color myColor = new Color(inputImg.getRGB(x, y));
System.out.println("Red: " + myColor.getRed());
System.out.println("Green: " + myColor.getGreen());
System.out.println("Blue: " + myColor.getBlue());
}
public static void main(String[] args) {
new Separator();
System.out.println("The End");
}
}
这是我使用的图片链接http://postimage.org/image/t6tvlv941/