Get pixel color on screen

97 Views Asked by At

How to use Jython (Robot) to get a pixel color in R,G,B format and then convert it to HEX.

This is my code so far.

import sys
import os
import java.awt.Robot
import java.awt.Color

def get_pixels(posX, posY):
    robot = Robot()
    Color = getPixelColor(posX, posY)

    r = color.getRed()
    g = color.getGreen()
    b =  color.getBlue()
    
    color =  "#{:02x}{:02x}{:02x}".format(r,g,b)
    
    return Color

    
get_pixels(200, 300)
1

There are 1 best solutions below

0
On BEST ANSWER

Well, i found out how to make it work, am gonna share my code anyways.

#Jython

import sys
import os
from java.awt import Robot, Color

def get_pixels(posX, posY):
  robot = Robot() 
  colors = robot.getPixelColor(posX, posY)   

  r = colors.getRed()
  g = colors.getGreen()
  b = colors.getBlue()

  colors =  "#{:02x}{:02x}{:02x}".format(r,g,b)
  print (colors)

get_pixels(500, 500)

Thanks, regards!