Search in sources :

Example 6 with ExifInterface

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);
    }
}
Also used : ErrnoException(android.system.ErrnoException) ExifInterface(android.media.ExifInterface) FileDescriptor(java.io.FileDescriptor)

Example 7 with ExifInterface

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;
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 8 with ExifInterface

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;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ExifInterface(android.media.ExifInterface)

Example 9 with ExifInterface

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);
}
Also used : ExifInterface(android.media.ExifInterface)

Example 10 with ExifInterface

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!");
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(android.media.ExifInterface)

Aggregations

ExifInterface (android.media.ExifInterface)153 IOException (java.io.IOException)93 Paint (android.graphics.Paint)32 Bitmap (android.graphics.Bitmap)26 InputStream (java.io.InputStream)21 File (java.io.File)17 BitmapFactory (android.graphics.BitmapFactory)16 Matrix (android.graphics.Matrix)15 FileInputStream (java.io.FileInputStream)15 Point (android.graphics.Point)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ErrnoException (android.system.ErrnoException)10 BufferedInputStream (java.io.BufferedInputStream)10 FileDescriptor (java.io.FileDescriptor)10 FileNotFoundException (java.io.FileNotFoundException)10 SuppressLint (android.annotation.SuppressLint)9 FileOutputStream (java.io.FileOutputStream)8 Cursor (android.database.Cursor)7 AssetFileDescriptor (android.content.res.AssetFileDescriptor)6 Bundle (android.os.Bundle)5