简体   繁体   English

将 adb screencap raw 转换为 png

[英]Convert adb screencap raw to png

I'm trying to avoid using screencap -p because it is at least 3 times slower than output raw .我试图避免使用screencap -p因为它至少比 output raw慢 3 倍。 But I am having difficulties in converting raw into png.但是我在将 raw 转换为 png 时遇到了困难。

import subprocess
import cv2
import numpy as np

output = subprocess.check_output(f'src\\adb\\adb -s {serial} shell screencap')
array = np.frombuffer(output[12:], np.uint8).reshape(720, 1280, 4)
image = cv2.cvtColor(array, cv2.COLOR_BGRA2RGB)

I got this exception:我得到这个例外:

Exception has occurred: ValueError
cannot reshape array of size 3691368 into shape (720,1280,4)

As I was writing the question, I read the exception again and realised it must be some formatting issues, such as \r\n instead of \n , causing the array size to be that weird number.当我写这个问题时,我再次阅读异常并意识到它一定是一些格式问题,例如\r\n而不是\n ,导致数组大小是那个奇怪的数字。

The solution is as simple as:解决方案很简单:

output = subprocess.check_output(f'src\\adb\\adb -s {serial} shell screencap').replace(b'\r\n', b'\n')

Hope this helps others.希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM