Android 整个手机屏幕截图和去除状态栏截图
一、去除状态栏截图
//整个手机屏幕的视图 View view = getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); // 获取状态栏高度 Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; Log.i("TAG", "" + statusBarHeight); // 获取屏幕长和高 int width = getWindowManager().getDefaultDisplay().getWidth(); int height = getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight); //保存图片 FileOutputStream fout = null; try {fout = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.png"); } catch (FileNotFoundException e) {e.printStackTrace(); }b.compress(Bitmap.CompressFormat.PNG, 100, fout); //显示截图 mImageView.setImageBitmap(b);
二、整个手机屏幕截图,但状态栏是空白
View view = getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); FileOutputStream fout = null; try {fout = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.png"); } catch (FileNotFoundException e) {e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout); mImageView.setImageBitmap(bitmap);
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
