找回密码
 立即注册
搜索
查看: 43|回复: 0

pyautogui对屏幕指定区域截屏

[复制链接]

52

主题

0

回帖

230

积分

管理员

积分
230
发表于 2025-8-7 17:09:30 | 显示全部楼层 |阅读模式
import pyautogui
import time

def capture_area(x1, y1, x2, y2,no):
    """根据坐标截图并保存"""
    try:
        # 确保坐标有效性
        left = min(x1, x2)
        top = min(y1, y2)
        right = max(x1, x2)
        bottom = max(y1, y2)

        # 计算区域尺寸
        width = right - left
        height = bottom - top

        # 截取屏幕区域
        screenshot = pyautogui.screenshot(region=(left, top, width, height))

        # 生成带时间戳的文件名
        filename = f"{no}.png"
        screenshot.save(filename)

        print(f"截图成功!保存为:{filename}")
        return filename
    except Exception as e:
        print(f"截图失败:{str(e)}")
        return None

if __name__ == "__main__":
    time.sleep(3)
    no=1
    while True:
        capture_area(370, 150, 2200, 1450,no)
        time.sleep(1)
        pyautogui.click(2412,1284)
        time.sleep(3)
        no=no+1
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

SKYPIEA

GMT+8, 2025-9-9 03:03 , Processed in 0.044396 second(s), 23 queries .

快速回复 返回顶部 返回列表