简体   繁体   English

如何从 Python 中的 PIL.ImageGrab.grab() 获取实际像素颜色值?

[英]How to get actual Pixel Color value from PIL.ImageGrab.grab() in Python?

I'm trying to take a Pixel color value from the screen in Python我正在尝试从 Python 中的屏幕获取像素颜色值

This is the example i'm doing to get the pixel at the position x=30 and y=30 on screen这是我在屏幕上获取 position x=30 和 y=30 处的像素的示例

def takePixel() :
    rgb = PIL.ImageGrab.grab().load()[30,30]

How do i print out and store the actual pixel color value from this?我如何从中打印出并存储实际的像素颜色值?

ImageGrab.grab returns a PIL.Image object, which has a getpixel method. ImageGrab.grab返回一个PIL.Image object,它有一个getpixel方法。

def takePixel():
    rgb = PIL.ImageGrab.grab().getpixel(30,30)
    return rgb
print(takePixel())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM