截取的是个bitmap图片
/** * 获取屏幕截图 * * @return */ public Bitmap getScreenShot() { // 获取windows中最顶层的view View view = getWindow().getDecorView(); view.buildDrawingCache(); // 获取状态栏高度 Rect rect = new Rect(); view.getWindowVisibleDisplayFrame(rect); int statusBarHeights = rect.top; Display display = getWindowManager().getDefaultDisplay(); // 获取屏幕宽和高 int widths = display.getWidth(); int heights = display.getHeight(); // 允许当前窗口保存缓存信息 view.setDrawingCacheEnabled(true); // 去掉状态栏 Bitmap bmp = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeights, widths, heights - statusBarHeights); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 10, bos); byte[] bytes = bos.toByteArray(); bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); // 销毁缓存信息 view.destroyDrawingCache(); return bmp; }