Android(安卓)针对View的截图操作
16lz
2021-01-24
实现对View的截图操作,核心代码如下:
Bitmap bitmap = null;FileOutputStream fileOutputStream = null;try {bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);Canvas canvas = new Canvas();canvas.setBitmap(bitmap);view.draw(canvas);fileOutputStream = new FileOutputStream(filePath);bitmap.compress(CompressFormat.PNG, 100, fileOutputStream);} catch (Exception e) {e.printStackTrace();} finally {if (bitmap != null && !bitmap.isRecycled()) {bitmap.recycle();bitmap = null;}if (fileOutputStream != null) {try {fileOutputStream.close();} catch (IOException e) {e.printStackTrace();}}}
例如:对整个窗口进行截图,可以使用下面代码获得窗口的View:
View windowView = (View) getWindow().getDecorView();
多说一句:希望对您有所帮助!:)
更多相关文章
- Android(安卓)数据库升级 数据迁移 数据不丢失
- 蓝牙最简单的例子,最难得的简单
- android 代码控制LinearLayout 宽度高度 报错widget.LinearLayou
- android 在Resources 中定义arrays
- Android(安卓)WebView 加载富文本内容
- android 模拟listview多线程下载进度条显示不干扰
- Android中定义的路径全局变量
- android Manifest 一些属性
- android中如何发送一个广播