使用Python屏幕截图ADB
因此,我试图截图ADB并纯粹是从Python截然不同的,因此用户设备上不会保存任何文件。
我创建了以下辅助功能以进行操作,
def adb_run(command, verbose=False):
result = subprocess.run([r"D:\Program Files\Nox\bin\adb.exe"] + command, stdout=subprocess.PIPE, errors="ignore")
if verbose:
print(result.stdout)
return result
def shell(command, verbose=False):
return adb_run(['shell', command], verbose)
def screencap():
return shell(f"screencap -p")
然后我打电话给screencap()
函数并将其写入文件,内容似乎是有效的png文件,但是我无法加载。 png文件既然它说已损坏了,
capped = screencap().stdout
with open("screencap.png", "wb") as f:
f.write(capped.encode())
有人知道为什么图像文件会损坏吗?我在网上没有找到任何纯Python解决方案
so I am trying to screenshot adb and handle it purely from Python hence there will be no files saved on the users device.
I created the following helper functions in order to do so
def adb_run(command, verbose=False):
result = subprocess.run([r"D:\Program Files\Nox\bin\adb.exe"] + command, stdout=subprocess.PIPE, errors="ignore")
if verbose:
print(result.stdout)
return result
def shell(command, verbose=False):
return adb_run(['shell', command], verbose)
def screencap():
return shell(f"screencap -p")
I then called the screencap()
function and wrote it to a file, the content seems to be a valid PNG file, but I am not able to load the png file since it says it's corrupted
capped = screencap().stdout
with open("screencap.png", "wb") as f:
f.write(capped.encode())
Does anyone know why the image file would be corrupted? I haven't found any pure python solutions online
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
exec-out
而不是shell
。Try using
exec-out
rather thanshell
.