所以我試圖截取 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解決方案
uj5u.com熱心網友回復:
嘗試使用exec-out而不是shell.
def screencap(filename):
return adb_run(['exec-out', f'screencap -p > {filename}'])
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/476908.html
上一篇:FlutterMethodChanelErrorjava.lang.RuntimeException:標有@UiThread的方法必須在主執行緒上執行
