public static Bitmap getBitmapFromFile(File file, int width, int height) {
BitmapFactory.Options opts = null;
if (null != file && file.exists()) {
if (width > 0 && height > 0) {
opts = new BitmapFactory.Options();
// 只是返回的是图片的宽和高,并不是返回一个Bitmap对象
opts.inJustDecodeBounds = true;
// 信息没有保存在bitmap里面,而是保存在options里面
BitmapFactory.decodeFile(file.getPath(), opts);
// 计算图片缩放比例
final int minSideLength = Math.min(width, height);
// 缩略图大小为原始图片大小的几分之一。根据业务需求来做。
opts.inSampleSize = computeSampleSize(opts, minSideLength,
width * height);
// 重新读入图片,注意此时已经把options.inJustDecodeBounds设回false
opts.inJustDecodeBounds = false;
// 设置是否深拷贝,与inPurgeable结合使用
opts.inInputShareable = true;
// 设置为True时,表示系统内存不足时可以被回 收,设置为False时,表示不能被回收。
opts.inPurgeable = true;
}
try {
return BitmapFactory.decodeFile(file.getPath(), opts);
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
}
return null;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有