Pyhton使用adb直接获取安卓手机screenshot,不保存成文件

版权声明:本文为博主原创文章,转载请联系作者 https://blog.csdn.net/u013832707/article/details/80631174

安卓开发配置教程

请参考:https://github.com/wangshub/wechat_jump_game/wiki/Android-和-iOS-操作步骤

使用Python调用adb相关

获取手机屏幕

process = subprocess.Popen('adb shell screencap -p', shell=True, stdout=subprocess.PIPE)
screenshot = process.stdout.read()
binary_screenshot = screenshot.replace(b'\r\n', b'\n')
img = cv2.imdecode(np.frombuffer(binary_screenshot, np.uint8), cv2.IMREAD_COLOR)

模拟按压

cmd = 'adb shell input swipe {x1} {y1} {x2} {y2} {duration}'.format(
        x1=swipe_x1,
        y1=swipe_y1,
        x2=swipe_x2,
        y2=swipe_y2,
        duration=press_time
    )
os.system(cmd)
展开阅读全文

没有更多推荐了,返回首页