Android Screenshort Take shot(Activity activity)

Here you can find the source of shot(Activity activity)

Description

shot

Declaration

public static Bitmap shot(Activity activity) 

Method Source Code


import android.app.Activity;

import android.graphics.Bitmap;
import android.graphics.Rect;

import android.view.Display;
import android.view.View;

public class Main {

    public static Bitmap shot(Activity activity) {
        View views = activity.getWindow().getDecorView();
        views.buildDrawingCache();//ww  w .  ja  v  a  2  s .  c  o m

        
        Rect frames = new Rect();
        views.getWindowVisibleDisplayFrame(frames);
        int statusBarHeights = frames.top;
        Display display = activity.getWindowManager().getDefaultDisplay();
        int widths = display.getWidth();
        int heights = display.getHeight();
        
        views.layout(0, statusBarHeights, widths, heights
                - statusBarHeights);
        views.setDrawingCacheEnabled(true);
        Bitmap bmp = Bitmap.createBitmap(views.getDrawingCache());
        
        
        
        
        return bmp;
    }
}

Related

  1. takeScreenShot(Activity activity)
  2. cutToScreen(Activity activity, Bitmap bitmap)
  3. snapShotWithoutStatusBar(Activity activity)
  4. snapShotWithStatusBar(Activity activity)