Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Pixel help - Java
  2. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  3. Rectangle screenRectangle = new Rectangle(screenSize);
  4. Robot robot = new Robot();
  5. BufferedImage image = robot.createScreenCapture(screenRectangle)
  6.  
  7.  
  8. int w = image.getWidth(null);
  9. int h = image.getHeight(null);
  10. int[] rgbs = new int[w*h];
  11. image.getRGB(0, 0, w, h, rgbs, 0, w);
  12. // find your pixel in the rgbs array
  13. for(int y=0;y<h;y++) {
  14.     for(int x=0;x<w;x++) {
  15.         if(rgbs[(y*w) + x] == mypixel) { // mypixel
  16.             robot.mouseMove(x, y);
  17.             robot.mousePress(InputEvent.BUTTON1_MASK);
  18.             robot.mouseRelease(InputEvent.BUTTON1_MASK);
  19.         }
  20.     }
  21. }
  22.        
  23. mypixel = new Color(red, green, blue).getRGB();