views:

1052

answers:

5

How to capture the android device screen content and make an image file using the snapshot data?which api I should use or where to find related resource? thanks in advance!

BTW: not camera snapshot,but device screen

A: 

In Java there is a Robot Class...which has a createScreenCapture(); method

Create a Object

Robot r = new Robot();

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

Rectangle rect = new Rectangle(dim);

BufferedImage image = robot.createScreenCapture(rect);

PS : I Think It Will Work On Android Too....

Vizay Soni
Robot class is not avaliable in android SDK.So..
Jagie
k...i didnt know that...
Vizay Soni
+1  A: 

According to this: http://www.mobilecrunch.com/2008/10/31/how-to-capture-the-screen-of-an-android-device/ you can use ddms in the tools directory of the android sdk to take screen captures.

If you want to do this from within your application and not during development, there are applications to do so, see Screenshot for an example. But as zed_0xff points out it certainly requires root.

Joubarc
+1  A: 

if you want to do screen capture from Java code in Android app AFAIK you must have Root provileges.

zed_0xff
A: 

AFAIK, All of the methods currently to capture a screenshot of android use the /dev/graphics/fb0 framebuffer. This includes ddms. It does require root to read from this stream. ddms uses adbd to request the information, so root is not required as adb has the permissions needed to request the data from /dev/graphics/fb0.

The framebuffer contains 2+ "frames" of RGB565 images. If you are able to read the data, you would have to know the screen resolution to know how many bytes are needed to get the image. each pixel is 2 bytes, so if the screen res was 480x800, you would have to read 768,000 bytes for the image, since a 480x800 RGB565 image has 384,000 pixels.

Ryan Conrad
A: 

You can try the following library: http://code.google.com/p/android-screenshot-library/ Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.

Kuba