Search in sources :

Example 96 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by AOSPA.

the class ExifInterfaceTest method testExifInterfaceCommon.

private void testExifInterfaceCommon(File imageFile, ExpectedValue expectedValue) throws IOException {
    String verboseTag = imageFile.getName();
    // Creates via path.
    ExifInterface exifInterface = new ExifInterface(imageFile.getAbsolutePath());
    compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    // Creates from an asset file.
    InputStream in = null;
    try {
        in = mContext.getAssets().open(imageFile.getName());
        exifInterface = new ExifInterface(in);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } finally {
        IoUtils.closeQuietly(in);
    }
    // Creates via InputStream.
    in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(imageFile.getAbsolutePath()));
        exifInterface = new ExifInterface(in);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } finally {
        IoUtils.closeQuietly(in);
    }
    // Creates via FileDescriptor.
    FileDescriptor fd = null;
    try {
        fd = Os.open(imageFile.getAbsolutePath(), OsConstants.O_RDONLY, 0600);
        exifInterface = new ExifInterface(fd);
        compareWithExpectedValue(exifInterface, expectedValue, verboseTag);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    } finally {
        IoUtils.closeQuietly(fd);
    }
}
Also used : ErrnoException(android.system.ErrnoException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(android.media.ExifInterface) FileInputStream(java.io.FileInputStream) FileDescriptor(java.io.FileDescriptor)

Example 97 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Bundle(android.os.Bundle) ExifInterface(android.media.ExifInterface) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 98 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.

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 99 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by ResurrectionRemix.

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 (IOException 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) IOException(java.io.IOException)

Example 100 with ExifInterface

use of android.media.ExifInterface in project android_frameworks_base by DirtyUnicorns.

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 (IOException 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) IOException(java.io.IOException)

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