问题
To get the RGB values from a pixel of the screen with coordinates (x,y) in Python, I do:
import PIL.ImageGrab
rgb = PIL.ImageGrab.grab().load()[x,y]
It was working as I expected until I did:
rgb = PIL.ImageGrab.grab().load()[1673,0]
Instead of the RGB values of the pixel, I received:
IndexError: image index out of range
I don't understand why because my screen has 1920x1080 resolution.
How can I fix this?
回答1:
If you do:
import PIL.ImageGrab
PIL.ImageGrab.grab().size
You will see the resolution that python is detecting in your system. If you are using Windows, you have to go to Screen Configuration and then change: text, aplications and another elements size to 100%.
If your resolution is 1920x1080 ,as you said, this should fix the problem.
来源:https://stackoverflow.com/questions/42636933/get-rgb-value-from-screen-pixels-with-python