@Override public Color getPixelColor(int x, int y) { return myRobot.getPixelColor(x, y); } }
// Global var Robot robot; MouseLocation() throws AWTException { robot = new Robot(); } public Color getMouseColor() { return robot.getPixelColor(x, y); }
public void mousePressed(MouseEvent e) { Robot robot = new Robot(); Color clickedColor = robot.getPixelColor(e.getX(),e.getY()); doSomething(clickedColor); }
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);
public Color getPixelColor(int x, int y) throws AWTException { Robot robot = new Robot(); return robot.getPixelColor(x, y); }
Robot robot = new Robot(); Color pixelColor = robot.getPixelColor(xPos, yPos);
/** 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); }
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); }
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));
// 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; }
@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)); } } });
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; } }
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()); } }
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())); }
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); }
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(); } } });
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); }
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); }
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); }
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); }