如何让python程序更快地截屏?

2024-06-01 20:54:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在做这个脚本,点击屏幕上某个颜色的像素,但我遇到了一个问题,当我循环这个时,它会截图,但只有大约12在30秒的循环,当它应该采取600程序点击像素非常快。我迷路了

xx = 0
while xx <= 600:
    with mss.mss() as sct:
        region = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080}
        imgg = sct.grab(region)
        img1 = mss.tools.to_png(imgg.rgb,imgg.size,output="C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack"+str(xx)+".png")
        imgname = "C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack"+str(xx)+".png"
    pxls = find_yellow_pixels(imgname)
    pyautogui.click(pxls[0],pxls[1])
    time.sleep(.05)
    xx = xx + 1

Tags: png像素usersregionxxdesktopmssstr
1条回答
网友
1楼 · 发布于 2024-06-01 20:54:44

首先,您应该重写以避免每次迭代都实例化一个新的MSS类,并删除休眠:

import mss

with mss.mss() as sct:
    region = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080}

    for xx in range(600):
        imgname = "C:/Users/yaahy/Desktop/scrnshotoutput/imageforgamehack" + str(xx) + ".png"
        imgg = sct.grab(region)
        img1 = mss.tools.to_png(imgg.rgb, imgg.size, output=imgname)
        # pxls = find_yellow_pixels(imgname)
        # pyautogui.click(pxls[0],pxls[1])

然后,正如评论者建议的那样,你应该解释你想要实现什么,也许你可以摆脱PNG的创建,直接使用原始数据。在

相关问题 更多 >