失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android编辑图片大小 android中Bitmap图像处理 修改图片大小以及保存时的文件大小...

android编辑图片大小 android中Bitmap图像处理 修改图片大小以及保存时的文件大小...

时间:2021-09-12 11:24:15

相关推荐

android编辑图片大小 android中Bitmap图像处理 修改图片大小以及保存时的文件大小...

Options options1 = new Options();

options1.inJustDecodeBounds = true;

BitmapFactory.decodeFile(filePath, options1);

options1.inSampleSize = RegisterTool.calculateInSampleSize(options1, 110, 160); //110,160:转换后的宽和高,具体值会有些出入

options1.inJustDecodeBounds = false;

Bitmap bitmap = BitmapFactory.decodeFile(filePath, options1); //filePath:文件路径

public static int calculateInSampleSize(BitmapFactory.Options options,

int reqWidth, int reqHeight) {

final int height = options.outHeight;

final int width = options.outWidth;

int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int heightRatio = Math.round((float) height

/ (float) reqHeight);

final int widthRatio = Math.round((float) width / (float) reqWidth);

inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;

}

return inSampleSize;

}

//压缩图片并将Bitmap保存到本地

FileOutputStream out = new FileOutputStream(new File(filePath));

press(pressFormat.JPEG, 60, out); //60代表压缩40%

如果觉得《android编辑图片大小 android中Bitmap图像处理 修改图片大小以及保存时的文件大小...》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。