/**
* Created by kingadmin on 2018/4/17.
*/
public class BitmapUtil {
private static BitmapUtil btimapUtil;
private Context context;
private BitmapUtil(Context context) {
this.context = context;
}
public static BitmapUtil getBtimapUtil(Context context) {
if (btimapUtil == null) {
synchronized (BitmapUtil.class) {
btimapUtil = new BitmapUtil(context);
}
}
return btimapUtil;
}
/**
* 文件转Bitmap
*/
public Bitmap fileToBitmap(String filePath) {
File file = new File(filePath);
BitmapFactory.Options options = new BitmapFactory.Options();
/**
*压缩长宽各为一半避免图片过大装载不了
*/
options.inPurgeable = true;
options.inSampleSize = 2;
return BitmapFactory.decodeFile(filePath, options);
}
/**
* Bitmap转文件
*/
public File bitmapToFile(Bitmap bitmap, String saveFilePath) {
File file = new File(saveFilePath);//将要保存图片的路径
try {
Android Bitmap最全基本操作:与Drawable 、File、btye[]互转
最新推荐文章于 2022-10-27 14:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)