【问题标题】:how to take screenshot in coordinates using adb如何使用 adb 在坐标中截取屏幕截图
【发布时间】:2022-12-23 03:51:10
【问题描述】:

我正在测试 android adb 以进行屏幕捕获。然后我可以全屏截图,现在我要捕捉坐标。我使用以下命令行: adb shell screencap -p -d 0 /sdcard/test.png 使用此命令行,我捕获了全屏。查阅了n+1个地方,得知下面的命令行是按坐标抓取的(坐标放在-d id后面) adb shell screencap -p -d 0 266 655 664 554 /sdcard/test.png

但是运行后返回结果如下,谁能帮帮我

usage: screencap [-hp] [-d display-id] [FILENAME]
   -h: this message
   -p: save the file as a png.
   -d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

【问题讨论】:

  • 捕获完整图像,然后使用其他命令行工具裁剪图像。例如,ImageMagick 可以做到这一点。
  • @CommonsWare 非常感谢你!

标签: python android android-emulator adb


【解决方案1】:

screencap 不接受帮助中明确指出的坐标。

-d 指定可以使用获取的显示ID

 dumpsys SurfaceFlinger --display-id

在单个显示设备上,您可以使用默认设置。

使用AndroidViewClient/culebra你可以做到这一点

#! /usr/bin/env python3

from com.dtmilano.android.viewclient import ViewClient


device, serialno = ViewClient.connectToDeviceOrExit()
device.takeSnapshot().crop((100, 50, 500, 600)).save('/tmp/myscreencap.png', 'PNG')

然后 /tmp/myscreencap.png 将包含裁剪框 (作为(左,上,右,下)).

但是,如果您想要实现的是获取特定视图的屏幕截图而不仅仅是随机坐标,您也可以使用View.writeImageToFile()

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多