Updating the ExifParsing code
> Using system implementation of ExifInterface to read orientation
> For inputstream, creating a temporary file with just the header
since the system API only supports file input
Change-Id: I19c94ff28e9d9bac14cd9b717de0ff165ba95595
This commit is contained in:
@@ -21,8 +21,6 @@ import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.gallery3d.exif.ExifInterface;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -42,38 +40,26 @@ public class BitmapUtils {
|
||||
}
|
||||
|
||||
public static int getRotationFromExif(Context context, Uri uri) {
|
||||
return BitmapUtils.getRotationFromExifHelper(null, 0, context, uri);
|
||||
return BitmapUtils.getRotationFromExifHelper(null, 0, uri, context);
|
||||
}
|
||||
|
||||
public static int getRotationFromExif(Resources res, int resId) {
|
||||
return BitmapUtils.getRotationFromExifHelper(res, resId, null, null);
|
||||
public static int getRotationFromExif(Resources res, int resId, Context context) {
|
||||
return BitmapUtils.getRotationFromExifHelper(res, resId, null, context);
|
||||
}
|
||||
|
||||
private static int getRotationFromExifHelper(Resources res, int resId, Context context, Uri uri) {
|
||||
ExifInterface ei = new ExifInterface();
|
||||
private static int getRotationFromExifHelper(Resources res, int resId,
|
||||
Uri uri, Context context) {
|
||||
InputStream is = null;
|
||||
BufferedInputStream bis = null;
|
||||
try {
|
||||
if (uri != null) {
|
||||
is = context.getContentResolver().openInputStream(uri);
|
||||
bis = new BufferedInputStream(is);
|
||||
ei.readExif(bis);
|
||||
} else {
|
||||
is = res.openRawResource(resId);
|
||||
bis = new BufferedInputStream(is);
|
||||
ei.readExif(bis);
|
||||
}
|
||||
Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
|
||||
if (ori != null) {
|
||||
return ExifInterface.getRotationForOrientationValue(ori.shortValue());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Getting exif data failed", e);
|
||||
} catch (NullPointerException e) {
|
||||
// Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
|
||||
return ExifOrientation.readRotation(new BufferedInputStream(is), context);
|
||||
} catch (IOException | NullPointerException e) {
|
||||
Log.w(TAG, "Getting exif data failed", e);
|
||||
} finally {
|
||||
Utils.closeSilently(bis);
|
||||
Utils.closeSilently(is);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user