use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.
the class ExifInterfaceTest method testSaveAttributes_withFileDescriptor.
private void testSaveAttributes_withFileDescriptor(File imageFile, ExpectedValue expectedValue) throws IOException {
String verboseTag = imageFile.getName();
FileDescriptor fd = null;
try {
fd = Os.open(imageFile.getAbsolutePath(), OsConstants.O_RDWR, 0600);
ExifInterface exifInterface = new ExifInterface(fd);
exifInterface.saveAttributes();
Os.lseek(fd, 0, OsConstants.SEEK_SET);
exifInterface = new ExifInterface(fd);
compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
// Test for modifying one attribute.
String backupValue = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
exifInterface.setAttribute(ExifInterface.TAG_MAKE, "abc");
exifInterface.saveAttributes();
Os.lseek(fd, 0, OsConstants.SEEK_SET);
exifInterface = new ExifInterface(fd);
assertEquals("abc", exifInterface.getAttribute(ExifInterface.TAG_MAKE));
// Restore the backup value.
exifInterface.setAttribute(ExifInterface.TAG_MAKE, backupValue);
exifInterface.saveAttributes();
Os.lseek(fd, 0, OsConstants.SEEK_SET);
exifInterface = new ExifInterface(fd);
compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
} catch (ErrnoException e) {
throw e.rethrowAsIOException();
} finally {
IoUtils.closeQuietly(fd);
}
}
use of android.media.ExifInterface in project UltimateAndroid by cymcsg.
the class CropUtil method copyExifRotation.
public static boolean copyExifRotation(File sourceFile, File destFile) {
if (sourceFile == null || destFile == null)
return false;
try {
ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
exifDest.saveAttributes();
return true;
} catch (IOException e) {
Log.e("Error copying Exif data", e);
return false;
}
}
use of android.media.ExifInterface in project xUtils by wyouflf.
the class BitmapCache method rotateBitmapIfNeeded.
private synchronized Bitmap rotateBitmapIfNeeded(String uri, BitmapDisplayConfig config, Bitmap bitmap) {
Bitmap result = bitmap;
if (config != null && config.isAutoRotation()) {
File bitmapFile = this.getBitmapFileFromDiskCache(uri);
if (bitmapFile != null && bitmapFile.exists()) {
ExifInterface exif = null;
try {
exif = new ExifInterface(bitmapFile.getPath());
} catch (Throwable e) {
return result;
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
int angle = 0;
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
angle = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
angle = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
angle = 270;
break;
default:
angle = 0;
break;
}
if (angle != 0) {
Matrix m = new Matrix();
m.postRotate(angle);
result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
bitmap.recycle();
bitmap = null;
}
}
}
return result;
}
use of android.media.ExifInterface in project android_frameworks_base by AOSPA.
the class ExifInterfaceTest method testSaveAttributes_withFileName.
private void testSaveAttributes_withFileName(File imageFile, ExpectedValue expectedValue) throws IOException {
String verboseTag = imageFile.getName();
ExifInterface exifInterface = new ExifInterface(imageFile.getAbsolutePath());
exifInterface.saveAttributes();
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
// Test for modifying one attribute.
String backupValue = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
exifInterface.setAttribute(ExifInterface.TAG_MAKE, "abc");
exifInterface.saveAttributes();
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
assertEquals("abc", exifInterface.getAttribute(ExifInterface.TAG_MAKE));
// Restore the backup value.
exifInterface.setAttribute(ExifInterface.TAG_MAKE, backupValue);
exifInterface.saveAttributes();
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
}
use of android.media.ExifInterface in project platform_frameworks_base by android.
the class ExifInterfaceTest method testSaveAttributes_withInputStream.
private void testSaveAttributes_withInputStream(File imageFile, ExpectedValue expectedValue) throws IOException {
InputStream in = null;
try {
in = getContext().getAssets().open(imageFile.getName());
ExifInterface exifInterface = new ExifInterface(in);
exifInterface.saveAttributes();
} catch (UnsupportedOperationException e) {
// created with InputStream.
return;
} finally {
IoUtils.closeQuietly(in);
}
fail("Should not reach here!");
}
Aggregations