使用python从屏幕像素获取RGB值 [英] Get RGB value from screen pixels with python

查看:1658
本文介绍了使用python从屏幕像素获取RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从屏幕的像素中获取具有python中坐标(x,y)的RGB值,我这样做:

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]

我收到的不是像素的RGB值:

Instead of the RGB values of the pixel, I received:

IndexError: image index out of range

我不明白为什么,因为我的屏幕分辨率为1920x1080.

I don't understand why because my screen has 1920x1080 resolution.

我该如何解决?

推荐答案

如果您这样做:

import PIL.ImageGrab
PIL.ImageGrab.grab().size

您将看到python在系统中检测到的分辨率.如果您使用的是Windows,则必须转到屏幕配置",然后将以下内容更改为:文本,应用和其他元素大小为100%.

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%.

如果您说的分辨率是1920x1080,则应该可以解决此问题.

If your resolution is 1920x1080 ,as you said, this should fix the problem.

这篇关于使用python从屏幕像素获取RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆