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

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.33 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. How can i get a larger area of pixels for the Robot.getPixelColor(x, y) method?
  2. import java.awt.Color;
  3. import java.awt.Robot;
  4.  
  5. public class Colour
  6. {
  7.     int    x, y;
  8.     int    n    = 0;
  9.     int    m    = 0;
  10.     int    i    = 0;
  11.  
  12.     public Colour()
  13.     {
  14.         try
  15.         {
  16.             Robot robot = new Robot();
  17.             Color targetColor = new Color(255, 25, 255);
  18.             Color color = robot.getPixelColor(n, n);
  19.  
  20.             while (color.getRGB() != targetColor.getRGB() && i != 1000)
  21.             {
  22.                 color = robot.getPixelColor(n, n);
  23.                 System.out.println("color = " + color);
  24.                 n++;
  25.                 i++;
  26.  
  27.                 if (color.getRGB() == targetColor.getRGB())
  28.                 {
  29.                     i = 1000;
  30.                     System.out.println("colour found" + n + " " + n);
  31.                 }
  32.             }
  33.         }
  34.         catch (Exception e)
  35.         {
  36.         }
  37.     }
  38.  
  39.     public static void main(String[] args)
  40.     {
  41.         Colour color = new Colour();
  42.     }
  43. }
  44.        
  45. for(int i=0;i<=1000;i++){
  46.     for(int j=0;j<=1000;j++){
  47.         color = robot.getPixelColor(i, j);
  48.         System.out.println("color = " + color);
  49.  
  50.         if(color.getRGB() == targetColor.getRGB()){
  51.             System.out.println("colour found" + i + " " + j);
  52.             i=1000;
  53.             break;
  54.         }
  55.     }
  56. }