Skip to content

Commit 7ecbbb6

Browse files
committed
Explicitly specify image rotation from EXIF
(SubsamplingScaleImageView.ORIENTATION_USE_EXIF doesn't always work for custom storage locations)
1 parent ea167b1 commit 7ecbbb6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

app/src/main/java/app/grapheneos/camera/ktx/SubsamplingScaleImageView.kt

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,42 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
77

88
fun SubsamplingScaleImageView.fixOrientationForImage(imageUri: Uri) {
99
val exifOrientation = getImageOrientationFromUri(context, imageUri)
10-
orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
1110
when (exifOrientation) {
1211
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> {
1312
scaleX = -1f
13+
orientation = SubsamplingScaleImageView.ORIENTATION_0
1414
}
15+
1516
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
1617
scaleY = -1f
18+
orientation = SubsamplingScaleImageView.ORIENTATION_0
1719
}
20+
1821
ExifInterface.ORIENTATION_TRANSVERSE -> {
1922
scaleX = -1f
23+
orientation = SubsamplingScaleImageView.ORIENTATION_270
2024
}
25+
2126
ExifInterface.ORIENTATION_TRANSPOSE -> {
2227
scaleX = -1f
28+
orientation = SubsamplingScaleImageView.ORIENTATION_90
29+
}
30+
31+
ExifInterface.ORIENTATION_ROTATE_90 -> {
32+
orientation = SubsamplingScaleImageView.ORIENTATION_90
2333
}
34+
35+
ExifInterface.ORIENTATION_ROTATE_180 -> {
36+
orientation = SubsamplingScaleImageView.ORIENTATION_180
37+
}
38+
39+
ExifInterface.ORIENTATION_ROTATE_270 -> {
40+
orientation = SubsamplingScaleImageView.ORIENTATION_270
41+
}
42+
43+
// ExifInterface.ORIENTATION_NORMAL and ExifInterface.ORIENTATION_UNDEFINED
44+
// don't need any handling as the image would be as expected (or the orientation
45+
// would be unknown which is unlikely since all the images displayed in our in-app
46+
// gallery are generated by our camera app)
2447
}
2548
}

0 commit comments

Comments
 (0)