09-03
04
屏幕某点颜色抓取
作者:Java伴侣 日期:2009-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();
}
}
}
}
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();
}
}
}
}
评论: 0 | 引用: 0 | 查看次数: 551
发表评论