首页 > 移动平台 > 详细

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

时间:2014-03-14 01:57:27      阅读:1149      评论:0      收藏:0      [点我收藏+]

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));
saveBitmap.compress(Bitmap.CompressFormat.JPEG, 60, out);   //60代表压缩40%








android中Bitmap图像处理 修改图片大小以及保存时的文件大小,布布扣,bubuko.com

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

原文:http://blog.csdn.net/centralperk/article/details/21185055

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!