1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cn.flightfeather.thirdapp.util.photo;
 
 
import android.media.ExifInterface;
 
/**
 * Super basic exif utilities.
 */
public class ExifHelper {
 
    /**
     * Maps an {@link ExifInterface} orientation value
     * to the actual degrees.
     */
    public static int getOrientation(int exifOrientation) {
        int orientation;
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_NORMAL:
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                orientation = 0; break;
 
            case ExifInterface.ORIENTATION_ROTATE_180:
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                orientation = 180; break;
 
            case ExifInterface.ORIENTATION_ROTATE_90:
            case ExifInterface.ORIENTATION_TRANSPOSE:
                orientation = 90; break;
 
            case ExifInterface.ORIENTATION_ROTATE_270:
            case ExifInterface.ORIENTATION_TRANSVERSE:
                orientation = 270; break;
 
            default: orientation = 0;
        }
        return orientation;
    }
 
    /**
     * Maps a degree value to {@link ExifInterface} constant.
     */
    public static int getExifOrientation(int orientation) {
        switch ((orientation + 360) % 360) {
            case 0: return ExifInterface.ORIENTATION_NORMAL;
            case 90: return ExifInterface.ORIENTATION_ROTATE_90;
            case 180: return ExifInterface.ORIENTATION_ROTATE_180;
            case 270: return ExifInterface.ORIENTATION_ROTATE_270;
            default: throw new IllegalArgumentException("Invalid orientation: " + orientation);
        }
    }
}