Advertisement
TheCodingKid

Get Pixel RGB

Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.MouseInfo;
  3. import java.awt.Point;
  4. import java.awt.Rectangle;
  5. import java.awt.Robot;
  6. import java.awt.Toolkit;
  7. import java.awt.event.KeyEvent;
  8. import java.awt.image.BufferedImage;
  9. import java.util.Random;
  10.  
  11.  
  12. public class Pxl {
  13.     public static void main(String[] argv) throws AWTException {
  14.         Robot bot = new Robot();
  15.         while(true) {
  16.  
  17.             System.out.println(MouseInfo.getPointerInfo().getLocation());
  18.             Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
  19.             Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  20.             BufferedImage capture = new Robot().createScreenCapture(screenRect);
  21.             double x = mouseLoc.getX();
  22.             double y = mouseLoc.getY();
  23.             System.out.println("x " + x);
  24.             System.out.println("y " + y);
  25.             int newPixel = capture.getRGB((int) x, (int) y);
  26.             printPixelARGB(newPixel, bot);
  27.         }
  28.     }
  29.  
  30.     public static void printPixelARGB(int pixel, Robot bot) {
  31.  
  32.         int alpha = (pixel >> 24) & 0xff;
  33.         int red = (pixel >> 16) & 0xff;
  34.         int green = (pixel >> 8) & 0xff;
  35.         int blue = (pixel) & 0xff;
  36.         System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
  37.  
  38.         if (red == 0 && green == 153 && blue == 0) {
  39.             bot.keyPress(KeyEvent.VK_SPACE); bot.keyRelease(KeyEvent.VK_SPACE); }
  40.         sleepMode(1000); }
  41.  
  42.     public static void sleepMode(int pauseLen) {
  43.         try {
  44.             Thread.sleep(pauseLen);
  45.         } catch(InterruptedException ex) {
  46.             Thread.currentThread().interrupt();
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement