开发者

Java - get pixel color

开发者 https://www.devze.com 2023-03-30 10:40 出处:网络
I am Java beginner and I am trying to code something. Currently I am stucked at getPixelColor(). It开发者_开发技巧\'s the method of class Robot. I can get pixel color but don\'t know how to compare wi

I am Java beginner and I am trying to code something. Currently I am stucked at 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. But I can't compare these two colors, because it throws this error "incomparable types:int and java.awt.Color". So how convert it to int?

Thanks


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.


Try

Color otherColor = new Color(someInt);

and then

if (otherColor.equals(robot.getPixelColor(someX, someY))
{
     ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消