问题描述
晚上好,
我想创建一个脚本,在我的屏幕上制作某个区域的屏幕截图。这是一个有很多动作的网站,我想测试一下。 如果屏幕截图中的像素为白色 (255,255,255),则它应该执行某些操作,但首先要打破循环。如果不是白色,则应重新截图,直到像素变为白色。
这是我制作的脚本:
import pyautogui
from PIL import Image
import time
current = pyautogui.screenshot(region=(949,502,10,5))
current.save("./current.png")
def rgb_of_pixel(img_path,x,y):
im = Image.open(img_path).convert('RGB')
r,g,b = im.getpixel((x,y))
a = (r,b)
return a
img = "./current.png"
print(rgb_of_pixel(img,1,1))
a = rgb_of_pixel(img,1)
while True:
if a == (255,255):
print('It is white!')
break
else:
print(rgb_of_pixel(img,1))
last = pyautogui.screenshot(region=(949,5))
last.save("./current.png")
time.sleep(0.5)
如果在我启动脚本时像素已经是白色的,它就可以工作。但是如果像素在运行之间发生变化,它就不起作用。控制台打印出最新的颜色,但不会中断循环。我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)