Android普通截屏(不包括状态栏内容但有状态栏占位)
来源:互联网 发布:window python编译器 编辑:程序博客网 时间:2024/05/16 17:44
public static Bitmap normalShot(Activity activity) { View decorView = activity.getWindow().getDecorView(); decorView.setDrawingCacheEnabled(true); decorView.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(decorView.getDrawingCache(), 0, 0, decorView.getMeasuredWidth(), decorView.getMeasuredHeight()); decorView.setDrawingCacheEnabled(false); decorView.destroyDrawingCache(); return bitmap; }
首先利用Window的getDecorView()方法获取到屏幕上包含状态栏部分和用户应用程序里的内容。[ Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that). ]
然后使用decorView.getDrawingCache()方法返回被缓存的bitmap。[ Returns the bitmap in which this view drawing is cached. ]
效果:
附:保存bitmap到外部存储[ 需要外部存储的读写权限 ]
public static void saveBitmap(Context context, Bitmap bitmap) { String fileName = System.currentTimeMillis() + ".png"; String storagePath = Environment.getExternalStorageDirectory().getPath(); if (storagePath == null) { storagePath = context.getFilesDir().getPath(); } String filePath = storagePath + "/Pictures/"; String imageFullName = filePath + fileName; try { if (bitmap != null) { File dir = new File(filePath); if (!dir.exists()) { dir.mkdirs(); } File file = new File(imageFullName); if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); if (fos != null) { bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
微信公众号,一起来玩耍,纯属娱乐,哈哈哈~~~
阅读全文
1 0
- Android普通截屏(不包括状态栏内容但有状态栏占位)
- Android普通截屏(不包括状态栏内容无状态栏占位仅包含应用程序)
- Android普通截屏(包括状态栏内容)
- android常见的屏幕工具,获取屏幕宽高,状态栏高,手机截屏(包括状态栏和不包括状态栏)
- Android 全屏 但是有状态栏
- android 在状态栏显示内容以及更改状态栏颜色
- 获得屏幕截图代码:不包括状态栏
- 将布局延伸到状态栏,可用但有缺陷
- Android:将布局的内容延伸到状态栏
- android 5.1状态栏添加截屏功能
- Android 状态栏
- Android 状态栏
- Android状态栏
- android 状态栏
- android状态栏
- Android 状态栏
- Android--获得屏幕高宽,屏幕截图(包括或不包括状态栏)
- Android 全屏 但是有状态栏(任务栏)
- 传值流程
- android Viewpager+TabLayout+Fragment遇到的问题记录
- java前后台之间传值的几种方式
- ubuntu下修改mysql的编码
- http https ftp tcp的区别
- Android普通截屏(不包括状态栏内容但有状态栏占位)
- 【Hadoop】HDFS的运行原理
- 以前的c#mvc框架改进 想法
- 单例模式
- 社交电商野蛮生长后 社交+电商将成为新的寡头
- 【转】我和Linux的前世今生
- nginx服务配置信息
- 干货教程 | 从0开始写"脉脉"(二)·底部导航栏
- android应用开机自启动及失败原因(BOOT_COMPLETED应用)