android 根据图片路径获取图片缩略图
16lz
2021-01-25
/** * 根据指定的图像路径和大小来获取缩略图 * * @param path 图像的路径 * @param maxWidth 指定输出图像的宽度 * @param maxHeight 指定输出图像的高度 * @return 生成的缩略图 */ public static Bitmap revitionImageSize(String path, int maxWidth, int maxHeight) throws IOException { Bitmap bitmap = null; try { BufferedInputStream in = new BufferedInputStream(new FileInputStream( new File(path))); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(in, null, options); in.close(); int i = 0; while (true) { if ((options.outWidth >> i <= maxWidth) && (options.outHeight >> i <= maxHeight)) { in = new BufferedInputStream( new FileInputStream(new File(path))); options.inSampleSize = (int) Math.pow(2.0D, i); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeStream(in, null, options); break; } i += 1; } } catch (Exception e) { return null; } return bitmap; }
更多相关文章
- Android(安卓)批量上传sd卡图片
- Eclipse下搭建android开发环境
- katalon设置Android(安卓)SDK路径
- Android的FastBoot的安装与环境变量设置
- Weex 初体验(2)-navigator android跳转
- Qt for Android(安卓)环境搭建方法
- android studio配置android开发环境
- android 百度地图集成sdk,混淆报错(最新)
- Android(安卓)Studio - local path doesn't exist