|
9 | 9 | import android.graphics.PointF; |
10 | 10 | import android.graphics.PorterDuff; |
11 | 11 | import android.graphics.Rect; |
| 12 | +import android.graphics.Matrix; |
| 13 | +import android.media.ExifInterface; |
12 | 14 | import android.os.Environment; |
13 | 15 | import android.util.Base64; |
14 | 16 | import android.util.Log; |
@@ -69,10 +71,30 @@ public boolean openImageFile(String filename, String directory, String mode) { |
69 | 71 | "drawable", |
70 | 72 | mContext.getPackageName()); |
71 | 73 | BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); |
| 74 | + File file = new File(filename, directory == null ? "" : directory); |
72 | 75 | Bitmap bitmap = res == 0 ? |
73 | | - BitmapFactory.decodeFile(new File(filename, directory == null ? "" : directory).toString(), bitmapOptions) : |
| 76 | + BitmapFactory.decodeFile(file.toString(), bitmapOptions) : |
74 | 77 | BitmapFactory.decodeResource(mContext.getResources(), res); |
75 | | - if(bitmap != null) { |
| 78 | + |
| 79 | + try { |
| 80 | + ExifInterface exif = new ExifInterface(file.getAbsolutePath()); |
| 81 | + Matrix matrix = new Matrix(); |
| 82 | + |
| 83 | + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); |
| 84 | + if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { |
| 85 | + matrix.postRotate(90); |
| 86 | + } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { |
| 87 | + matrix.postRotate(180); |
| 88 | + } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { |
| 89 | + matrix.postRotate(270); |
| 90 | + } |
| 91 | + |
| 92 | + bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // rotating bitmap |
| 93 | + } catch (Exception e) { |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + if (bitmap != null) { |
76 | 98 | mBackgroundImage = bitmap; |
77 | 99 | mOriginalHeight = bitmap.getHeight(); |
78 | 100 | mOriginalWidth = bitmap.getWidth(); |
|
0 commit comments