use of android.media.ExifInterface in project ttdj by soonphe.
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 ttdj by soonphe.
the class ExifInterfaceCompat method getExifOrientation.
/**
* Read exif info and get orientation value of the photo.
*
* @param filepath to get exif.
* @return exif orientation value
*/
public static int getExifOrientation(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 EXIF_DEGREE_FALLBACK_VALUE;
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, EXIF_DEGREE_FALLBACK_VALUE);
if (orientation == EXIF_DEGREE_FALLBACK_VALUE) {
return 0;
}
// We only recognize a subset of orientation tag values.
switch(orientation) {
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 taquindroid by remram44.
the class ImageTools method getOrientation.
public static int getOrientation(Context context, Uri photoUri) {
try {
InputStream istream = context.getContentResolver().openInputStream(photoUri);
if (istream == null)
return ExifInterface.ORIENTATION_UNDEFINED;
File outputDir = context.getCacheDir();
String extension = getExtension(photoUri.getPath());
File tempfile = File.createTempFile("taquindroid", extension, outputDir);
FileOutputStream ostream = new FileOutputStream(tempfile);
byte[] buffer = new byte[4096];
int len;
while ((len = istream.read(buffer)) != -1) ostream.write(buffer, 0, len);
ostream.close();
istream.close();
ExifInterface exif = new ExifInterface(tempfile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
if (!tempfile.delete())
Log.e("TAQUINDROID", String.format("Couldn't delete teporary file %s", tempfile.getAbsolutePath()));
return orientation;
} catch (IOException e) {
Log.e("TAQUINDROID", "Error reading image orientation");
return ExifInterface.ORIENTATION_UNDEFINED;
}
}
use of android.media.ExifInterface in project Remindy by abicelis.
the class EditImageAttachmentActivity method checkExifAndFixImageRotation.
private void checkExifAndFixImageRotation() {
try {
ExifInterface ei = new ExifInterface(new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename()).getAbsolutePath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
mRotation = 90;
applyPendingRotation();
break;
case ExifInterface.ORIENTATION_ROTATE_180:
mRotation = 180;
applyPendingRotation();
break;
case ExifInterface.ORIENTATION_ROTATE_270:
mRotation = 270;
applyPendingRotation();
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
break;
}
// ei.setAttribute(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
} catch (IOException e) {
/*Do nothing*/
}
}
use of android.media.ExifInterface in project Lazy by l123456789jy.
the class BitmapUtil method getImageDegree.
/**
* 读取图片属性:图片被旋转的角度
*
* @param path 图片绝对路径
* @return 旋转的角度
*/
public static int getImageDegree(String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
Aggregations