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

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. Options options1 = new Options();  
  2. options1.inJustDecodeBounds = true;    
  3. BitmapFactory.decodeFile(filePath, options1);    
  4. options1.inSampleSize = RegisterTool.calculateInSampleSize(options1, 110160);  //110,160:转换后的宽和高,具体值会有些出入  
  5. options1.inJustDecodeBounds = false;    
  6. Bitmap bitmap = BitmapFactory.decodeFile(filePath, options1);       //filePath:文件路径  
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. public static int calculateInSampleSize(BitmapFactory.Options options,  
  2.             int reqWidth, int reqHeight) {  
  3.           
  4.         final int height = options.outHeight;  
  5.         final int width = options.outWidth;  
  6.         int inSampleSize = 1;  
  7.   
  8.         if (height > reqHeight || width > reqWidth) {  
  9.   
  10.             final int heightRatio = Math.round((float) height  
  11.                     / (float) reqHeight);  
  12.             final int widthRatio = Math.round((float) width / (float) reqWidth);  
  13.   
  14.             inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;  
  15.         }  
  16.   
  17.         return inSampleSize;  
  18.     }  
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //压缩图片并将Bitmap保存到本地  
  2. FileOutputStream out = new FileOutputStream(new File(filePath));  
  3. saveBitmap.compress(Bitmap.CompressFormat.JPEG, 60, out);   //60代表压缩40%  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值