use of android.media.ExifInterface in project WordPress-Android by wordpress-mobile.
the class ImageUtils method getExifOrientation.
public static int getExifOrientation(String path) {
ExifInterface exif;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
AppLog.e(AppLog.T.UTILS, e);
return 0;
}
int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
switch(exifOrientation) {
case ExifInterface.ORIENTATION_NORMAL:
return 0;
case ExifInterface.ORIENTATION_ROTATE_90:
return 90;
case ExifInterface.ORIENTATION_ROTATE_180:
return 180;
case ExifInterface.ORIENTATION_ROTATE_270:
return 270;
default:
return 0;
}
}
use of android.media.ExifInterface in project platform_frameworks_base by android.
the class DocumentsContract method openImageThumbnail.
/**
* Open the given image for thumbnail purposes, using any embedded EXIF
* thumbnail if available, and providing orientation hints from the parent
* image.
*
* @hide
*/
public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException {
final ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
Bundle extras = null;
try {
final ExifInterface exif = new ExifInterface(file.getAbsolutePath());
switch(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
case ExifInterface.ORIENTATION_ROTATE_90:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 270);
break;
}
final long[] thumb = exif.getThumbnailRange();
if (thumb != null) {
return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras);
}
} catch (IOException e) {
}
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras);
}
use of android.media.ExifInterface in project JamsMusicPlayer by psaravan.
the class FileBitmapHunter method getFileExifRotation.
static int getFileExifRotation(Uri uri) throws IOException {
ExifInterface exifInterface = new ExifInterface(uri.getPath());
int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL);
switch(orientation) {
case ORIENTATION_ROTATE_90:
return 90;
case ORIENTATION_ROTATE_180:
return 180;
case ORIENTATION_ROTATE_270:
return 270;
default:
return 0;
}
}
use of android.media.ExifInterface in project RxImagePicker by qingmei2.
the class ExifInterfaceCompat method getExifDateTime.
private static Date getExifDateTime(String filepath) {
ExifInterface exif;
try {
// ExifInterface does not check whether file path is null or not,
// so passing null file path argument to its constructor causing SIGSEGV.
// We should avoid such a situation by checking file path string.
exif = newInstance(filepath);
} catch (IOException ex) {
Log.e(TAG, "cannot read exif", ex);
return null;
}
String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
if (TextUtils.isEmpty(date)) {
return null;
}
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
return formatter.parse(date);
} catch (ParseException e) {
Log.d(TAG, "failed to parse date taken", e);
}
return null;
}
use of android.media.ExifInterface in project RxImagePicker by qingmei2.
the class PhotoMetadataUtils method shouldRotate.
private static boolean shouldRotate(ContentResolver resolver, Uri uri) {
ExifInterface exif;
try {
exif = ExifInterfaceCompat.newInstance(getPath(resolver, uri));
} catch (IOException e) {
Log.e(TAG, "could not read exif info of the image: " + uri);
return false;
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
return orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270;
}
Aggregations