Android 来自 adb 的 Nexus One 的屏幕截图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2807070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:28:51  来源:igfitidea点击:

Screenshot of the Nexus One from adb?

androidgraphicsffmpegscreenshot

提问by Marcus

My goal is to be able to type a one word command and get a screenshot from a rooted Nexus One attached by USB.

我的目标是能够输入一个单词命令并从 USB 连接的有根的 Nexus One 中获取屏幕截图。

So far, I can get the framebuffer which I believe is a 32bit xRGB888raw image by pulling it like this:

到目前为止,我可以32bit xRGB888通过像这样拉动它来获得我认为是原始图像的帧缓冲区:

adb pull /dev/graphics/fb0 fb0

From there though, I'm having a hard time getting it converted to a png. I'm trying with ffmpeg like this:

不过,从那里开始,我很难将其转换为 png。我正在尝试像这样使用 ffmpeg:

ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb8888 -s 480x800 -i fb0 -f image2 -vcodec png image.png

That creates a lovely purple image that has parts that vaguely resemble the screen, but it's by no means a clean screenshot.

这会创建一个可爱的紫色图像,它的部分与屏幕有些相似,但这绝不是一个干净的屏幕截图。

回答by Ben Clayton

A vastly easier solution for ICS is to use the following from the command line

ICS 的一个更简单的解决方案是从命令行使用以下内容

adb shell /system/bin/screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png screenshot.png

This'll save the screenshot.png file in the current directory.

这会将 screenshot.png 文件保存在当前目录中。

Tested on a Samsung Galaxy SII & SII running 4.0.3.

在运行 4.0.3 的三星 Galaxy SII 和 SII 上进行测试。

回答by Andrey Starodubtsev

Actually, there is another very simple ability to grab screenshot from your android device: write simple script 1.scriptlike this:

实际上,还有另一个非常简单的功能可以从您的 android 设备中抓取屏幕截图:编写这样的简单脚本1.script

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Takes a screenshot
result = device.takeSnapshot()

# Writes the screenshot to a file
result.writeToFile('1.png','png')

and call monkeyrunner 1.script.

并调用monkeyrunner 1.script

回答by Olivier

It seems that frame buffer of N1 uses RGB32 encoding (32 bits per pixel).

N1 的帧缓冲区似乎使用 RGB32 编码(每像素 32 位)。

Here is my script using ffmpeg:

这是我使用 ffmpeg 的脚本:

adb pull /dev/graphics/fb0 fb0
dd bs=1920 count=800 if=fb0 of=fb0b
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 480x800 -i fb0b -f image2 -vcodec png fb0.png

Another way derived from ADP1 method described here http://code.lardcave.net/entries/2009/07/27/132648/

从这里描述的 ADP1 方法派生的另一种方法http://code.lardcave.net/entries/2009/07/27/132648/

adb pull /dev/graphics/fb0 fb0
dd bs=1920 count=800 if=fb0 of=fb0b
python rgb32torgb888.py <fb0b >fb0b.888
convert -depth 8 -size 480x800 RGB:fb0b.888 fb0.png

Python script 'rgb32torgb888.py':

Python 脚本“rgb32torbb888.py”:

import sys
while 1:
 colour = sys.stdin.read(4)
 if not colour:
  break
 sys.stdout.write(colour[2])
 sys.stdout.write(colour[1])
 sys.stdout.write(colour[0])

回答by Cowan

Using my HTC Hero (and hence adjusting from 480x800 to 320x480), this works if I use rgb565 instead of 8888:

使用我的 HTC Hero(因此从 480x800 调整到 320x480),如果我使用 rgb565 而不是 8888,这会起作用:

ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 320x480 -i fb0 -f image2 -vcodec png image.png

回答by user3058757

If you have dos2unix installed, then the below

如果你安装了 dos2unix,那么下面的

adb shell screencap -p | dos2unix > screen.png

回答by parthiban

Now we have got a single line command to take a screenshot. The command as follows:

现在我们有一个单行命令来截取屏幕截图。命令如下:

adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

Type the above command in your terminal and press enter. If you want the screenshot to be stored in any specific location, then give the path (or) directory before screen.png.

在终端中输入上述命令并按回车键。如果要将屏幕截图存储在任何特定位置,请在screen.png.

Source.

来源

回答by Yann Ramin

I believe all framebuffers to date are RGB 565, not 888.

我相信迄今为止所有的帧缓冲区都是 RGB 565,而不是 888。

回答by Andry

rgb565instead of 8888also work on emulator

rgb565而不是8888也在模拟器上工作

回答by clsung

I think rgb32torgb888.py should be

我认为 rgb32torbb888.py 应该是

 sys.stdout.write(colour[0])
 sys.stdout.write(colour[1])
 sys.stdout.write(colour[2])

回答by Patola

I hope my script might be of any use. I use it on my galaxy tab and it works perfectly, but it is possible for you to change the default resolution. It requires the "zsh" shell, though:

我希望我的脚本可能有用。我在我的星系选项卡上使用它,它运行良好,但您可以更改默认分辨率。不过,它需要“zsh”外壳:

#!/bin/zsh

# These settings are for the galaxy tab.
HRES=600
VRES=1024

usage() {
  echo "Usage: ##代码## [ -p ] outputfile.png"
  echo "-- takes screenshot off your Galaxy Tab Android phone."
  echo " -p: portrait mode"
  echo " -r X:Y: specify resolution, e.g. -r 480:640 specifies that your cellphone has 480x640 resolution."
  exit 1
}

PORTRAIT=0 # false by default

umask 022

[[ ! -w . ]] && {
  echo "*** Error: current directory not writeable."
  usage
}

[[ ! -x $(which mogrify) ]] && {
  echo "*** Error: ImageMagick (mogrify) is not in the PATH!"
  usage
}

while getopts "pr:" myvar
do
  [[ "$myvar" == "p" ]] && PORTRAIT=1
  [[ "$myvar" == "r" ]] && {
    testhres="${OPTARG%%:*}" # remove longest-matching :* from end
    testvres="${OPTARG##*:}" # remove longest-matchung *: from beginning
    if [[ $testhres == <0-> && $testvres == <0-> ]] # Interval: from 0 to infinite. Any value would be: <->
    then
      HRES=$testhres
      VRES=$testvres
    else
      echo "Error! One of these values - '${testhres}' or '${testvres}' - is not numeric!"
      usage
    fi
  }
done
shift $((OPTIND-1))

[[ $# < 1 ]] && usage

outputfile=""

blocksize=$((HRES*4))
count=$((VRES))

adb pull /dev/graphics/fb0 fb0.$$
/bin/dd bs=$blocksize count=$count if=fb0.$$ of=fb0b.$$
/usr/bin/ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s ${VRES}x${HRES} -i fb0b.$$ -f image2 -vcodec png "${outputfile}"

if (( ${PORTRAIT} ))
then
  mogrify -rotate 270 "${outputfile}"
else
  mogrify -flip -flop "${outputfile}"
fi

/bin/rm -f fb0.$$ fb0b.$$