三星note3 拍照图片转向问题。解决oom

来源:互联网 发布:c语言基本数据类型包括 编辑:程序博客网 时间:2024/04/30 15:20
/** * 读取图片属性:旋转的角度 *  * @param path *            图片绝对路径 * @return degree旋转的角度 */public static int readPictureDegree(String path) {int degree = 0;try {ExifInterface exifInterface = new ExifInterface(path);int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);switch (orientation) {case ExifInterface.ORIENTATION_ROTATE_90:degree = 90;break;case ExifInterface.ORIENTATION_ROTATE_180:degree = 180;break;case ExifInterface.ORIENTATION_ROTATE_270:degree = 270;break;}} catch (IOException e) {e.printStackTrace();}return degree;}

/** * 旋转图片 *  * @param angle * @param bitmap * @return Bitmap */public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {// 旋转图片 动作Matrix matrix = new Matrix();matrix.postRotate(angle);System.out.println("angle2=" + angle);// 创建新的图片Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,bitmap.getWidth(), bitmap.getHeight(), matrix, true);return resizedBitmap;}
//该方法压缩显示图片和解决转向问题。
public static void setImageSrc(ImageView imageView, String imagePath,int angle) {BitmapFactory.Options option = new BitmapFactory.Options();option.inSampleSize = getImageScale(imagePath);Bitmap bm = BitmapFactory.decodeFile(imagePath, option);// 旋转图片 动作Matrix matrix = new Matrix();matrix.postRotate(angle);System.out.println("angle2=" + angle);// 创建新的图片Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), matrix, true);imageView.setImageBitmap(resizedBitmap);}private static int IMAGE_MAX_WIDTH = 480;private static int IMAGE_MAX_HEIGHT = 960;/** * scale image to fixed height and weight *  * @param imagePath * @return */private static int getImageScale(String imagePath) {BitmapFactory.Options option = new BitmapFactory.Options();// set inJustDecodeBounds to true, allowing the caller to query the// bitmap info without having to allocate the// memory for its pixels.option.inJustDecodeBounds = true;BitmapFactory.decodeFile(imagePath, option);int scale = 1;while (option.outWidth / scale >= IMAGE_MAX_WIDTH|| option.outHeight / scale >= IMAGE_MAX_HEIGHT) {scale *= 2;}return scale;}



1 0
原创粉丝点击