python-mss 截图简单示例
python-mss 是一个速度非常快的截图和录像工具,支持跨平台,使用纯 python 语言开发。
1 | pip install mss |
截取指定区域并保存为png
1 2 3 4 5 6 7 8 | #encoding=utf-8 import mss with mss.mss() as sct: box ={ "top" :50, "left" :50, "width" :200, "height" :200} im = sct.grab(box) mss.tools.to_png(im.rgb,im.size,output= "1.png" ) |
获取一个或多个像素点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #encoding=utf-8 import mss from PIL import Image with mss.mss() as sct: box ={ "top" :0, "left" :0, "width" :200, "height" :200} sct_img = sct.grab(box) #pixel = sct_img.pixel(0, 0) #print(pixel) img = Image. new ( "RGB" , sct_img.size) pixels = zip(sct_img.raw[2::4], sct_img.raw[1::4], sct_img.raw[::4]) a = list(pixels) #print(a) img.putdata(a) #img.show() |
监控某区域出现像素点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #encoding=utf-8 import mss,time from PIL import Image with mss.mss() as sct: box ={ "top" :70, "left" :220, "width" :9, "height" :12} while True: time.sleep(0.2)#不希望太快了 sct_img = sct.grab(box) img = Image. new ( "RGB" , sct_img.size) pixels = zip(sct_img.raw[2::4], sct_img.raw[1::4], sct_img.raw[::4]) a = list(pixels) if (192,0,192) in a: print( "出现" ) else : print( "消失" ) |
更多详细资料请参考官方链接 https://github.com/BoboTiG/python-mss
参考:https://blog.csdn.net/qq_34160248/article/details/127001100
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
2019-03-15 golang 日期时间处理
2019-03-15 golang json 读写配置文件