Capture the whole screen shot of one activity - Android Activity

Android examples for Activity:Activity Feature

Description

Capture the whole screen shot of one activity

Demo Code


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.view.View;

public class Main {
  /**/*from  www .  j  ava  2 s.  c  o  m*/
   * Capture the whole screen shot of one activity
   * 
   * @param act
   *          The activity
   * @return Screen shot bitmap
   */
  public static Bitmap captureScreenShot(Activity act) {

    View rootView = act.getWindow().getDecorView().getRootView();

    return captureScreenShot(rootView);
  }

  /**
   * Capture screen shot
   * 
   * @param rootView
   *          The root view. All UIs (screen range) under this root view would be
   *          captured.
   * @return Screen shot bitmap *
   */
  public static Bitmap captureScreenShot(View rootView) {

    Bitmap bitmap = Bitmap.createBitmap(rootView.getWidth(), rootView.getHeight(), Config.ARGB_8888);

    rootView.draw(new Canvas(bitmap));

    return bitmap;
  }
}

Related Tutorials