[英]Java - get pixel color
I am Java beginner and I am trying to code something. 我是Java初学者,正在尝试编写一些东西。 Currently I am stucked at getPixelColor(). 目前,我被困在getPixelColor()上。 It's the method of class Robot. 这是机器人类的方法。 I can get pixel color but don't know how to compare with other color. 我可以得到像素颜色,但不知道如何与其他颜色进行比较。 Let's say that my other color is stored in some int variable and I need to compare these two colors. 假设我的其他颜色存储在一些int变量中,我需要比较这两种颜色。 But I can't compare these two colors, because it throws this error "incomparable types:int and java.awt.Color". 但是我无法比较这两种颜色,因为它会引发此错误“无法比较的类型:int和java.awt.Color”。 So how convert it to int? 那么如何将其转换为int?
Thanks 谢谢
Try 尝试
Color otherColor = new Color(someInt);
and then 接着
if (otherColor.equals(robot.getPixelColor(someX, someY))
{
...
}
Probably something like: 大概是这样的:
if(color.getRGB() == stored_color){
}
Anyways, you need to access the Color object's getRGB function to compare the numeric value to another int. 无论如何,您都需要访问Color对象的getRGB函数以将数值与另一个int进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.