Android Bitmap保存 以及 屏幕截取工具类
来源:互联网 发布:python hdfs 编辑:程序博客网 时间:2024/06/08 03:05
import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Point;import android.graphics.Rect;import android.view.View;import com.acmenxd.logger.Logger;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;/** * @author AcmenXD * @version v1.0 * @github https://github.com/AcmenXD * @date 2016/11/23 16:09 * @detail Bitmap工具类 */public class BitmapUtils { /** * 截取屏幕(全屏)并保存 * * @param pActivity * @param isSaveStatusBar 是否保留状态栏 * @param pSavePath 保存路径 */ public static void saveScreenAsImage(Activity pActivity, boolean isSaveStatusBar, File pSavePath) { View pView = pActivity.getWindow().getDecorView(); pView.setDrawingCacheEnabled(true); pView.buildDrawingCache(); Bitmap srcBitmap = pView.getDrawingCache(); // 图片大小 Point point = new Point(); pActivity.getWindowManager().getDefaultDisplay().getSize(point); int width = pView.getWidth();//point.x; int height = pView.getHeight();//point.y; // 标题栏高度 int statusBarHeight = 0; if (isSaveStatusBar == false) { Rect frame = new Rect(); pActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); statusBarHeight = frame.top; height = height - statusBarHeight; } // 创建存储的bitmap Bitmap bitmap = Bitmap.createBitmap(srcBitmap, 0, statusBarHeight, width, height); // 清理掉缓存图片,防止内存溢出 pView.destroyDrawingCache(); // 保存图片 saveBitmap(bitmap, pSavePath); } /** * 保存图片到存储盘 -> 创建临时文件名称 * * 图片名为随机的 JPEG 格式图片 */ public static void saveBitmap(Bitmap pBitmap, File savePath) { saveBitmap(pBitmap, savePath, String.valueOf(RandomUtils.getRandomByTime()) + ".jpg", null); } /** * 保存图片到存储盘 * * @param pBitmap 存储的bitmap对象 * @param savePath 存储路径 * @param fileName 文件名 (带后缀名) * @param format 图片格式 (默认 JPEG 格式) */ public static void saveBitmap(Bitmap pBitmap, File savePath, String fileName, Bitmap.CompressFormat format) { if (format == null) { format = Bitmap.CompressFormat.JPEG; } // 保存图片 FileOutputStream fos = null; try { fos = new FileOutputStream(new File(savePath, fileName)); if (fos != null) { pBitmap.compress(format, 100, fos); fos.flush(); } } catch (IOException pE) { Logger.e(pE); } finally { IOUtils.closeQuietly(fos); } }}
0 0
- Android Bitmap保存 以及 屏幕截取工具类
- Android截屏幕实现,截取屏幕为bitmap,并保存进手机图库,activity之间传递bitmap对象
- Android屏幕尺寸以及相关工具类
- 截取当前屏幕获得Bitmap
- Android Bitmap 工具类
- Android Bitmap 工具类
- android 保存当前屏幕或者view为图片bitmap
- Android截取当前屏幕保存到外部设备上
- Android:实现截取当前屏幕图片并保存至SDCard
- android 截取当前屏幕保存到sd卡中
- Android屏幕相关以及尺寸的转换工具类
- android 图片处理工具类,Bitmap转换String ,Drawable, byte[],保存,优化等。
- android bitmap 缓存工具类
- 使用ReadPixels方法,实现对游戏截取任意位置的屏幕,以及保存和显示截取结果
- android截取屏幕图
- android截取屏幕图
- android 怎么截取屏幕
- android 截取屏幕
- 七牛的时间戳防盗链go语言
- 分库分表珠讥
- RxAndroid的使用方式(一)
- vue组件化开发初体验-示例vue-loader-example学习记录
- rails callback介绍
- Android Bitmap保存 以及 屏幕截取工具类
- 【2016东莞信息特长生】字串距离
- Maven在默认的源码包的基础上增加自己定义的源码包
- OpenStack基础原理
- springMVC fromdata表单上传文件+ajax ajaxSetup loading效果
- highcharts图表 去掉highcharts的logo 改变y轴的刻度 改变背景颜色 去掉图例
- 外贸电商:除了paypal,这些支付方式也能帮到你!
- Android内存优化 OOM
- .net一般应用处理程序