use of com.android.gallery3d.exif.ExifInterface in project android_frameworks_base by ResurrectionRemix.
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 AOSPA.
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 getExif.
public static List<ExifTag> getExif(Context context, Uri uri) {
String path = getLocalPathFromUri(context, uri);
if (path != null) {
Uri localUri = Uri.parse(path);
String mimeType = getMimeType(localUri);
if (!JPEG_MIME_TYPE.equals(mimeType)) {
return null;
}
try {
ExifInterface exif = new ExifInterface();
exif.readExif(path);
List<ExifTag> taglist = exif.getAllTags();
return taglist;
} catch (IOException e) {
Log.w(LOGTAG, "Failed to read EXIF tags", e);
} catch (NullPointerException e) {
Log.e(LOGTAG, "Failed to read EXIF tags", e);
}
}
return null;
}
use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.
the class LocalImage method rotate.
@Override
public void rotate(int degrees) {
GalleryUtils.assertNotInRenderThread();
Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
ContentValues values = new ContentValues();
int rotation = (this.rotation + degrees) % 360;
if (rotation < 0)
rotation += 360;
if (mimeType.equalsIgnoreCase("image/jpeg")) {
ExifInterface exifInterface = new ExifInterface();
ExifTag tag = exifInterface.buildTag(ExifInterface.TAG_ORIENTATION, ExifInterface.getOrientationValueForRotation(rotation));
if (tag != null) {
exifInterface.setTag(tag);
try {
exifInterface.forceRewriteExif(filePath);
fileSize = new File(filePath).length();
values.put(Images.Media.SIZE, fileSize);
} catch (FileNotFoundException e) {
Log.w(TAG, "cannot find file to set exif: " + filePath);
} catch (IOException e) {
Log.w(TAG, "cannot set exif data: " + filePath);
}
} else {
Log.w(TAG, "Could not build tag: " + ExifInterface.TAG_ORIENTATION);
}
}
values.put(Images.Media.ORIENTATION, rotation);
mApplication.getContentResolver().update(baseUri, values, "_id=?", new String[] { String.valueOf(id) });
}
use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.
the class Exif method getOrientation.
/**
* Returns the degrees in clockwise. Values are 0, 90, 180, or 270.
*/
public static int getOrientation(InputStream is) {
if (is == null) {
return 0;
}
ExifInterface exif = new ExifInterface();
try {
exif.readExif(is);
Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
if (val == null) {
return 0;
} else {
return ExifInterface.getRotationForOrientationValue(val.shortValue());
}
} catch (IOException e) {
Log.w(TAG, "Failed to read EXIF orientation", e);
return 0;
}
}
Aggregations