Wednesday, September 25, 2013

Capturing Screen shots on Android via ADB

Let's use screencap tool on Android to capture a screen shot and save it to a file on Android's internal /sdcard.

adb shell screencap -p /sdcard/myScreenShot.png

Ok, lets capture a series of screen shots - a movie.

adb shell mkdir -p /sdcard/moovie1; 
for i in `seq -w 1 1 155`; do \
  adb shell screencap -p /sdcard/moovie1/cap_$i.png && \
  echo -e "cap_$i.png"; \
done;

Now let's download the images:

for i in `seq -w 1 1 155`; do \
  adb pull /sdcard/moovie1/cap_$i.png && \
  adb shell rm /sdcard/moovie1/cap_$i.png && \
  echo -e "cap_$i.png\n"; \
done;

Ok, now let's make a movie with help of well-known imagemagick tool::
Scale images to 50% size and convert them to GIF format.

for i in `ls`; \
  do convert $i -scale 50% $i.gif; \
done;

convert -delay 100 -loop 0 cap*.gif animated_screen.gif

Also one could use following script to save captured images directly to computer

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

to cat images directly to a file on a computer (src)
(but for series of screen shots that will be a bit slower).


adb shell screencap -h
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.


No comments:

Post a Comment