700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Android 整个手机屏幕截图和去除状态栏截图

Android 整个手机屏幕截图和去除状态栏截图

时间:2021-05-15 00:04:15

相关推荐

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(); }press(pressFormat.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();}press(pressFormat.PNG, 100, fout);mImageView.setImageBitmap(bitmap);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。