Screenshot of the Nexus One from adb?

35,076

Solution 1

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

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.

Tested on a Samsung Galaxy SII & SII running 4.0.3.

Solution 2

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

# 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.

Solution 3

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

Here is my script using 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/

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':

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])

Solution 4

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

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

Solution 5

If you have dos2unix installed, then the below

adb shell screencap -p | dos2unix > screen.png
Share:
35,076

Related videos on Youtube

Christian Landivar
Author by

Christian Landivar

Developer / UX Specialist in Seattle, WA.

Updated on July 09, 2022

Comments

  • Christian Landivar
    Christian Landivar almost 2 years

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

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

    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:

    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.

  • Christian Landivar
    Christian Landivar about 14 years
    Yeah, it works for me on the Magic/Dream/Hero but not on the N1. Thanks though.
  • Julio Gorgé
    Julio Gorgé over 13 years
    Yes, I had to swap the R and B channels to get correct colors from my N1.
  • Patola
    Patola over 13 years
    I was not very clear -- it will (probably) work on ANY android if you provide the resolution.
  • Jørgen R
    Jørgen R over 11 years
    Works on SE Xperia X10 as well.
  • ce4
    ce4 over 11 years
    Faster: adb shell screencap -p \| uuencode o | uudecode -o out.png (needs linux+uudecode though, base64 also works)
  • Jade
    Jade almost 11 years
    @ce4, you should write-up your comment as an answer. It is the best answer for this question.
  • ce4
    ce4 almost 11 years
    @Benjamin this question has already >10 answers... and its just an improvement of Ben's answer suitable only for linux users.
  • BVB
    BVB over 10 years
    This is my favorite method - very simply! I set up an alias for everything but the filename for easy use whenever I need to take a screenshot.
  • The Compiler
    The Compiler about 10 years
    The answer by @ce4 takes about 1-2 seconds longer per picture for me, so YMMV (unless the intention was being faster to type).
  • Ángel
    Ángel about 7 years
    This is probably only accurate for Windows, where it will "helpfully" translate LF to CRLF withint its C runtime by default. On other OS, running dos2unix there would corrupt the png
  • parthiban
    parthiban over 6 years
    Thank you Sir Pedro Brasileiro.