Last active
December 22, 2015 15:29
-
-
Save lenciel/6492947 to your computer and use it in GitHub Desktop.
Android如何命令行进行截屏
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一般 Android 用户都知道同时按下音量减和电源键的屏幕截图方式,不过作为开发者,可能需要一个更为简便的方式将屏幕截图保存至开发电脑上。 | |
该方式仅需在终端执行一条命令即可,涉及调用系统内置的 screencap 工具: | |
``` | |
adb shell screencap -p | sed 's/\r$//' > screen.png | |
``` | |
screencap 本身支持标准输出,所以可以用管道符链接。但是 adb shell 会将结果中的 LF 转换为 CR+LF(为了兼容性考虑?),于是会将 png 的格式破坏。于是这里使用行编辑器 sed 将 LF 前的 CR 移除。 | |
若您使用 OS X,也可以使用 perl 实现类似效果: | |
``` | |
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment