take Screen Shot - Android android.app

Android examples for android.app:Screen

Description

take Screen Shot

Demo Code

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

public class Main {

  /**/*  w w  w .j  a va2 s.  c  om*/
   * Also see
   * http://stackoverflow.com/questions/10296711/androidtake-screenshot-and-share-it
   * 
   * @param activity
   * @return
   */
  public static Bitmap takeScreenShot(Activity activity) {
    View rootView = activity.getWindow().getDecorView();
    Bitmap bmp = Bitmap.createBitmap(rootView.getWidth(), rootView.getHeight(), Bitmap.Config.RGB_565);
    rootView.draw(new Canvas(bmp));
    // Remove title bar
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    bmp = Bitmap.createBitmap(bmp, 0, statusBarHeight, rootView.getWidth(), rootView.getHeight() - statusBarHeight);
    return bmp;
  }

}

Related Tutorials