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%








更多相关文章

  1. Android 7.0调用相机拍照并获取图片路径
  2. android加载文件的方式,路径的写法
  3. android的路径问题
  4. Android Studio 中如何更改SDK路径
  5. Android 获取assets的绝对路径
  6. Android 获取路径
  7. Android将获取到文件的uri转换为字符串的路径

随机推荐

  1. android开发中常用的五大布局
  2. 最易用的 Android(安卓)HTTP library
  3. Android五个布局
  4. 初探Android
  5. EditText 报出 “This text field does n
  6. Google Developing for Android(安卓)三
  7. Android(安卓)Framework 基础理解
  8. Android(安卓)EditView属性
  9. 转载 android 利用ksoap2方式连接webserv
  10. android UI小结(二)