use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.
the class SaveImage method getExifData.
public ExifInterface getExifData(Uri source) {
ExifInterface exif = new ExifInterface();
String mimeType = mContext.getContentResolver().getType(mSelectedImageUri);
if (mimeType == null) {
mimeType = ImageLoader.getMimeType(mSelectedImageUri);
}
if (ImageLoader.JPEG_MIME_TYPE.equals(mimeType)) {
InputStream inStream = null;
try {
inStream = mContext.getContentResolver().openInputStream(source);
exif.readExif(inStream);
} catch (FileNotFoundException e) {
Log.w(LOGTAG, "Cannot find file: " + source, e);
} catch (IOException e) {
Log.w(LOGTAG, "Cannot read exif for: " + source, e);
} catch (NullPointerException e) {
Log.w(LOGTAG, "Invalid exif data for: " + source, e);
} finally {
Utils.closeSilently(inStream);
}
}
return exif;
}
use of com.android.gallery3d.exif.ExifInterface in project platform_frameworks_base by android.
the class WallpaperCropActivity method getRotationFromExifHelper.
private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
ExifInterface ei = new ExifInterface();
InputStream is = null;
BufferedInputStream bis = null;
try {
if (path != null) {
ei.readExif(path);
} else 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(LOGTAG, "Getting exif data failed", e);
} catch (NullPointerException e) {
// Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
Log.w(LOGTAG, "Getting exif data failed", e);
} finally {
Utils.closeSilently(bis);
Utils.closeSilently(is);
}
return 0;
}
use of com.android.gallery3d.exif.ExifInterface in project android_frameworks_base by DirtyUnicorns.
the class WallpaperCropActivity method getRotationFromExifHelper.
private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
ExifInterface ei = new ExifInterface();
InputStream is = null;
BufferedInputStream bis = null;
try {
if (path != null) {
ei.readExif(path);
} else 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(LOGTAG, "Getting exif data failed", e);
} catch (NullPointerException e) {
// Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
Log.w(LOGTAG, "Getting exif data failed", e);
} finally {
Utils.closeSilently(bis);
Utils.closeSilently(is);
}
return 0;
}
use of com.android.gallery3d.exif.ExifInterface in project android_frameworks_base by crdroidandroid.
the class WallpaperCropActivity method getRotationFromExifHelper.
private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
ExifInterface ei = new ExifInterface();
InputStream is = null;
BufferedInputStream bis = null;
try {
if (path != null) {
ei.readExif(path);
} else 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(LOGTAG, "Getting exif data failed", e);
} catch (NullPointerException e) {
// Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
Log.w(LOGTAG, "Getting exif data failed", e);
} finally {
Utils.closeSilently(bis);
Utils.closeSilently(is);
}
return 0;
}
use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.
the class ImageLoader method getMetadataOrientation.
/**
* Returns the image's orientation flag. Defaults to ORI_NORMAL if no valid
* orientation was found.
*/
public static int getMetadataOrientation(Context context, Uri uri) {
if (uri == null || context == null) {
throw new IllegalArgumentException("bad argument to getOrientation");
}
// First try to find orientation data in Gallery's ContentProvider.
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor != null && cursor.moveToNext()) {
int ori = cursor.getInt(0);
switch(ori) {
case 90:
return ORI_ROTATE_90;
case 270:
return ORI_ROTATE_270;
case 180:
return ORI_ROTATE_180;
default:
return ORI_NORMAL;
}
}
} catch (SQLiteException e) {
// Do nothing
} catch (IllegalArgumentException e) {
// Do nothing
} catch (IllegalStateException e) {
// Do nothing
} finally {
Utils.closeSilently(cursor);
}
ExifInterface exif = new ExifInterface();
InputStream is = null;
// Fall back to checking EXIF tags in file or input stream.
try {
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
String mimeType = getMimeType(uri);
if (!JPEG_MIME_TYPE.equals(mimeType)) {
return ORI_NORMAL;
}
String path = uri.getPath();
exif.readExif(path);
} else {
is = context.getContentResolver().openInputStream(uri);
exif.readExif(is);
}
return parseExif(exif);
} catch (IOException e) {
Log.w(LOGTAG, "Failed to read EXIF orientation", e);
} catch (NullPointerException e) {
Log.w(LOGTAG, "Invalid EXIF data", e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
Log.w(LOGTAG, "Failed to close InputStream", e);
}
}
return ORI_NORMAL;
}
Aggregations