打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
对当前Activity进行截屏的封装代码
// 获取指定Activity的截屏,保存到png文件 private static Bitmap takeScreenShot(Activity activity) { // View是你需要截图的View View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); // 获取状态栏高度 Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; System.out.println(statusBarHeight); // 获取屏幕长和高 int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); // 去掉标题栏 Bitmap b = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; } // 保存到sdcard private static void savePic(Bitmap b, String strFileName) { FileOutputStream fos = null; try { fos = new FileOutputStream(strFileName); if (null != fos) { b.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void shoot(Activity activity) { ScreenShot.savePic(ScreenShot.takeScreenShot(activity), 'sdcard/apic/image' + System.currentTimeMillis() + '.png'); } } </pre>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Android截屏保存png图片的实例代码
将Canvas保存为一个bitmap
Android下常见的内存泄露
android 调用本地微信自定义多图分享朋友圈,可放在share sdk中一起使用
【收藏篇】Android 开发中常用的10种工具类
Activity 之间传递 Bitmap 大于40M的解决方法(传递map对象的解决方法)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服