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) {
|
||||
int orientation = 0;
|
||||
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())
|
||||
orientation = cursor.getInt(0);
|
||||
cursor.close();
|
||||
} catch (Exception ignore) {
|
||||
orientation = getExifOrientation(resolver, uri);
|
||||
}
|
||||
return orientation;
|
||||
}
|
||||
|
||||
private int getExifOrientation(ContentResolver resolver, Uri uri) {
|
||||
int orientation = 0;
|
||||
InputStream in = null;
|
||||
try {
|
||||
ExifInterface exif = new ExifInterface(uri.getPath());
|
||||
orientation = Utility.convertToDegrees(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0));
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue