获取指定Activity的截屏,保存到png文件
来源:互联网 发布:清华大学软件学院校友 编辑:程序博客网 时间:2024/05/24 04:57
/** * 获取指定Activity的Bitmap截屏 */ private Bitmap takeScreenShot(Activity activity) { // View是你需要截图的View View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); // 获取状态栏高度 Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; // 获取屏幕长和高 int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height=activity.getWindowManager().getDefaultDisplay().getHeight(); // 去掉标题栏 // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, b1.getWidth(), height - statusBarHeight); view.destroyDrawingCache(); return b; }
/** * 保存bitmap到sd卡 * @param bitmap * @param strFilePath 文件路径 * */ private void savePic(Bitmap bitmap, String strFilePath) { FileOutputStream fos = null; try { fos = new FileOutputStream(strFilePath); if (null != fos) { bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); File file=new File(strFilePath); //通知手机图库刷新本地相册 this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(file))); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
0 0
- 获取指定Activity的截屏,保存到png文件
- 获取指定Activity的截屏,保存到png文件
- ScreenShot获取指定Activity的截屏,保存到png文件
- IOS截屏一个UIView,以png或者jpg格式保存到指定目录下
- 从指定网络地址获取已知文件并保存到指定位置-指定文件名字和类型
- android Bitmap保存到文件(PNG)
- JAVA 服务器端的文件保存到客户端指定目录
- 把生成的json文件保存到指定项目文件夹
- MFC 使用CImage获取到屏幕截图,指定格式保存到文件
- 获取Bitmap保存到指定文件夹路径
- 把文件流中的图片按指定的大小保存到指定的文件中
- python某一目录下指定格式的文件路径保存到指定格式的文件中
- C# Visual Studio 2005中让保存文件对话框将文件保存到指定的文件夹
- 将上传文件保存到指定目录
- android 保存bitmap到指定文件
- 保存Log4j日志文件到指定路径
- cvSaveImage()保存图像到指定文件
- android 保存图片到指定文件
- 【数据结构】堆&优先级队列
- 有符号数的应用场合
- android studio导入Module
- spark运行原理和RDD解密
- shader 光照模型,半角向量
- 获取指定Activity的截屏,保存到png文件
- java Number 方法 运算符
- spring的annotation
- memcache基本使用
- XPP3-一个非常快的XML解析器
- 事件分发机制原理
- 找不到 constraint-layout:1.0.0-alpha3
- iOS文件拷贝实现
- Network Link Conditioner模拟不同网络环境