本文整理了Java中java.awt.Robot.getPixelColor
方法的一些代码示例,展示了Robot.getPixelColor
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Robot.getPixelColor
方法的具体详情如下:
包路径:java.awt.Robot
类名称:Robot
方法名:getPixelColor
暂无
代码示例来源:origin: pavelfatin/typometer
@Override
public Color getPixelColor(int x, int y) {
return myRobot.getPixelColor(x, y);
}
}
代码示例来源:origin: stackoverflow.com
// Global var
Robot robot;
MouseLocation() throws AWTException {
robot = new Robot();
}
public Color getMouseColor() {
return robot.getPixelColor(x, y);
}
代码示例来源:origin: stackoverflow.com
public void mousePressed(MouseEvent e)
{
Robot robot = new Robot();
Color clickedColor = robot.getPixelColor(e.getX(),e.getY());
doSomething(clickedColor);
}
代码示例来源:origin: stackoverflow.com
Robot robot = new Robot();
int xValue = slider.getLocationOnScreen().x + (int)(slider.getValue()/(double)(slider.getMaximum()-slider.getMinimum()) * slider.getWidth() +.5);//Calculates distance of the sliders' position).
int yValue = slider.getLocationOnScreen().y + slider.getHeight()/2;//Calculates a y-value to extract the pixel from.
Color color = robot.getPixelColor(xValue,yValue);
代码示例来源:origin: stackoverflow.com
public Color getPixelColor(int x, int y) throws AWTException {
Robot robot = new Robot();
return robot.getPixelColor(x, y);
}
代码示例来源:origin: stackoverflow.com
Robot robot = new Robot();
Color pixelColor = robot.getPixelColor(xPos, yPos);
代码示例来源:origin: abbot/abbot
/** Sample the color at the given point on the screen. */
public Color sample(int x, int y) {
// Service mode always returns black when sampled
if (robot != null && !serviceMode) {
// Make sure we sync the graphics
Toolkit.getDefaultToolkit().sync();
//
return robot.getPixelColor(x, y);
}
String msg = Strings.get("tester.Robot.no_sample");
throw new UnsupportedOperationException(msg);
}
代码示例来源:origin: pavelfatin/typometer
private static void delete(Robot robot, ScreenAccessor accessor, Point point, int count)
throws BenchmarkException, InterruptedException {
Color previousColor = robot.getPixelColor(point.x, point.y);
type(robot, KeyEvent.VK_BACK_SPACE, count);
waitForChange(accessor, point.x, point.y, previousColor);
sleep(DELETION_DELAY);
}
代码示例来源:origin: stackoverflow.com
long tm=System.currentTimeMillis();
int i;
Toolkit it=Toolkit.getDefaultToolkit();
Dimension d=it.getScreenSize();
int w=(int)d.getWidth(), h=(int)d.getHeight();
Rectangle rect=new Rectangle(0, 0, w, h);
Robot r=null;
try {
r=new Robot();
}
catch(AWTException awte){ };
BufferedImage ib=r.createScreenCapture(rect);
int[] pix=ib.getRGB(0, 0, w, h, null, 0, w);
for(i=0; i<pix.length; i++) pix[i]=pix[i]&0x00ffffff;
System.out.println("t1 "+(System.currentTimeMillis()-tm));
tm=System.currentTimeMillis();
for(i=0; i<pix.length; i++) r.getPixelColor(i%w, i/w);
System.out.println("t2 "+(System.currentTimeMillis()-tm));
代码示例来源:origin: stackoverflow.com
// Note rename of method to be more descriptive
public int[] getColorComponents(int xIn, int yIn)
{
int[] components = new int[3];
// accepts position of color, returns size 3 array of red green blue
// integers
try
{
Robot r = new Robot();
Color x = r.getPixelColor(xIn, yIn);
components[0] = x.getRed();
components[1] = x.getGreen();
components[2] = x.getBlue();
}
catch (AWTException e)
{
e.printStackTrace();
}
return components;
}
代码示例来源:origin: openpnp/openpnp
@Override
public void mouseMoved(MouseEvent e) {
Color color = robot.getPixelColor(e.getXOnScreen(), e.getYOnScreen());
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
Point p = matView.scalePoint(e.getPoint());
Object model = getModelAtPoint(p);
if (model != null) {
matStatusLabel.setText(model.toString());
}
else {
matStatusLabel.setText(String.format("RGB: %03d, %03d, %03d HSB: %03d, %03d, %03d XY: %d, %d",
color.getRed(),
color.getGreen(),
color.getBlue(),
(int) (255.0 * hsb[0]),
(int) (255.0 * hsb[1]),
(int) (255.0 * hsb[2]),
p.x,
p.y));
}
}
});
代码示例来源:origin: stackoverflow.com
public class color1
{
public color1()
{
}
public int[] getCol(int xIn, int yIn)
{
// accepts position of color, returns size 3 array of red green blue
// integers
int[] color = new int[3]; // Has to be here because of how you're (not) handling exceptions
try
{
Robot r = new Robot();
Color x = r.getPixelColor(xIn, yIn);
color[0] = x.getRed();
color[1] = x.getGreen();
color[2] = x.getBlue();
}
catch (AWTException e)
{
e.printStackTrace();
}
return color;
}
}
代码示例来源:origin: stackoverflow.com
import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
public class Test {
public static void main(String[] args) throws Exception {
while (true) {
try {
System.out.println(getPointerColor());
Thread.sleep(1000);
} catch (AWTException awte) {
System.out.println("Error while getting pointer's color!");
} catch (InterruptedException ie) {
System.out.println("Error while sleeping!");
}
}
}
public static Color getPointerColor() throws AWTException {
Point coordinates = MouseInfo.getPointerInfo().getLocation();
Robot robot = new Robot();
return robot.getPixelColor((int) coordinates.getX(), (int) coordinates.getX());
}
}
代码示例来源:origin: stackoverflow.com
import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
public class Main {
public static String getHexString(int rgb) {
String hexString = Integer.toHexString(rgb);
hexString = hexString.length() > 1 ? hexString : "0" + hexString;
return hexString;
}
public static void main(String[] a) throws AWTException {
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
Color color = new Robot().getPixelColor(mouseLocation.x,
mouseLocation.y);
System.out.println(getHexString(color.getRed())
+ getHexString(color.getGreen())
+ getHexString(color.getBlue()));
}
代码示例来源:origin: org.xworker/xworker_core
public static Object getPixelColor(ActionContext actionContext){
Thing self = (Thing) actionContext.get("self");
java.awt.Robot robot = (java.awt.Robot) self.doAction("getRobot", actionContext);
Point point = (Point) self.doAction("getPoint", actionContext);
return robot.getPixelColor(point.x, point.y);
}
代码示例来源:origin: stackoverflow.com
JLabel.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent me){
try {
Robot robot = new Robot();
if(JLabel.getBounds().contains(me.getPoint()) && !robot.getPixelColor(me.getXOnScreen(),me.getYOnScreen()).equals(page.getBackground())){
//Do action here
}
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
代码示例来源:origin: org.java.net.substance/substance
protected void pickFinish() {
pickerTimer.stop();
pickerFrame.setVisible(false);
PointerInfo info = MouseInfo.getPointerInfo();
Point loc = info.getLocation();
Color c = robot.getPixelColor(loc.x + pickOffset.x, loc.y
+ pickOffset.y);
getColorSelectionModel().setSelectedColor(c);
}
代码示例来源:origin: com.github.insubstantial/substance
protected void pickFinish() {
pickerTimer.stop();
pickerFrame.setVisible(false);
PointerInfo info = MouseInfo.getPointerInfo();
if (info == null) return; //pointer not on a graphics device
Point loc = info.getLocation();
Color c = robot.getPixelColor(loc.x + pickOffset.x, loc.y
+ pickOffset.y);
getColorSelectionModel().setSelectedColor(c);
}
代码示例来源:origin: com.github.insubstantial/substance
protected void pickFinish() {
pickerTimer.stop();
pickerFrame.setVisible(false);
PointerInfo info = MouseInfo.getPointerInfo();
if (info == null) return; //pointer not on a graphics device
Point loc = info.getLocation();
Color c = robot.getPixelColor(loc.x + pickOffset.x, loc.y
+ pickOffset.y);
getColorSelectionModel().setSelectedColor(c);
}
代码示例来源:origin: org.java.net.substance/substance
protected void pickFinish() {
pickerTimer.stop();
pickerFrame.setVisible(false);
PointerInfo info = MouseInfo.getPointerInfo();
Point loc = info.getLocation();
Color c = robot.getPixelColor(loc.x + pickOffset.x, loc.y
+ pickOffset.y);
getColorSelectionModel().setSelectedColor(c);
}
内容来源于网络,如有侵权,请联系作者删除!