09-03
04

屏幕某点颜色抓取

package 娱乐.桌面;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
public class PickColor extends JFrame implements Runnable{
private Robot robot;
private Color color = new Color(0, 0, 0);
private Point point;
private JPanel pane = new JPanel();
private JLabel label = new JLabel();

public PickColor(String title)
{
super(title);
label.setHorizontalAlignment(JLabel.CENTER);
getContentPane().add(pane, "Center");
getContentPane().add(label, "South");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,200);
setVisible(true);
new Thread(this).start();
}
public static void main(String[] args)
{
PickColor pc = new PickColor("PickColor");
}

public void run()
{
while(true)
{
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try
{
robot = new Robot();
point = MouseInfo.getPointerInfo().getLocation();
color = robot.getPixelColor(point.x, point.y); //获取某坐标的颜色
pane.setBackground(color);
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")");// 获取颜色的值··你可以判读该值的大小判断是不是你需要的颜色
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}

文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 屏幕 抓取 GUI
相关日志:
评论: 0 | 引用: 0 | 查看次数: 553
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭