public static String get450File(String mStrPicPath) { int angel = UtilImage.readPictureDegree(mStrPicPath); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(mStrPicPath, options); bmp = null; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; int scale = 1; if (options.outWidth > UtilFile.BITMAP_WIDTH_SHOW) scale = (int) (options.outWidth / UtilFile.BITMAP_WIDTH_SHOW); options.inSampleSize = scale; bmp = BitmapFactory.decodeFile(mStrPicPath, options); /** 把图片旋转为正的方向 */ bmp = UtilImage.rotaingImageView(angel, bmp); String str_dir = UtilFile.getFolderPath(UtilFile.DIR_PHOTO_CACHE); File dir = new File(str_dir); File filepic = new File(dir, System.currentTimeMillis() + ".jpg"); try { bmp.compress(CompressFormat.JPEG, 100, new FileOutputStream(filepic)); } catch (FileNotFoundException e) { e.printStackTrace(); } // 回收bitmap recycleBitmap(bmp); if (filepic != null) return filepic.toString(); return ""; }
public static void rotateAndReplaceOldImageFile(String mStrPicPath) { int angel = UtilImage.readPictureDegree(mStrPicPath); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(mStrPicPath, options); bmp = null; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; int scale = (int) (options.outWidth / UtilFile.BITMAP_WIDTH_SHOW); options.inSampleSize = scale; bmp = BitmapFactory.decodeFile(mStrPicPath, options); /** 把图片旋转为正的方向 */ bmp = UtilImage.rotaingImageView(angel, bmp); try { bmp.compress(CompressFormat.PNG, 100, new FileOutputStream(new File(mStrPicPath))); } catch (FileNotFoundException e) { e.printStackTrace(); } // 回收bitmap recycleBitmap(bmp); }