mirror of
https://github.com/olgamiller/SSTVEncoder2.git
synced 2025-12-06 06:52:01 +01:00
Fixed image orientation error
(replaced uri.getPath with InputStream as argument of ExifInterface)
This commit is contained in:
parent
da7c59063a
commit
e333e2124e
|
|
@ -273,16 +273,33 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public int getOrientation(ContentResolver resolver, Uri uri) {
|
public int getOrientation(ContentResolver resolver, Uri uri) {
|
||||||
int orientation = 0;
|
int orientation = 0;
|
||||||
try {
|
try {
|
||||||
Cursor cursor = resolver.query(uri, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
|
Cursor cursor = resolver.query(uri,
|
||||||
|
new String[]{MediaStore.Images.ImageColumns.ORIENTATION},
|
||||||
|
null, null, null);
|
||||||
if (cursor.moveToFirst())
|
if (cursor.moveToFirst())
|
||||||
orientation = cursor.getInt(0);
|
orientation = cursor.getInt(0);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
try {
|
orientation = getExifOrientation(resolver, uri);
|
||||||
ExifInterface exif = new ExifInterface(uri.getPath());
|
}
|
||||||
orientation = Utility.convertToDegrees(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0));
|
return orientation;
|
||||||
} catch (Exception ex) {
|
}
|
||||||
showOrientationErrorMessage(uri, ex);
|
|
||||||
|
private int getExifOrientation(ContentResolver resolver, Uri uri) {
|
||||||
|
int orientation = 0;
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = resolver.openInputStream(uri);
|
||||||
|
int orientationAttribute = (new ExifInterface(in)).getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
|
||||||
|
orientation = Utility.convertToDegrees(orientationAttribute);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
showOrientationErrorMessage(uri, ex);
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return orientation;
|
return orientation;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue