android实现截屏

private Bitmap shot(Activity activity) { 
       //View是你需要截图的View 
		 View view = activity.getWindow().getDecorView(); 
		 view.setDrawingCacheEnabled(true); 
         view.buildDrawingCache(); 
         Bitmap b1 = view.getDrawingCache(); 
       // 获取状态栏高度 /
		   Rect frame = new Rect();
		 activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
         int statusBarHeight = frame.top;
         Log.i("TAG", "" + statusBarHeight);
         // 获取屏幕长和高
         int width = activity.getWindowManager().getDefaultDisplay().getWidth();
         int height = activity.getWindowManager().getDefaultDisplay().getHeight();
        // 去掉标题栏
			Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
         Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
		view.destroyDrawingCache();
         return b;
    }

你可能感兴趣的:(android)