Search in sources :

Example 21 with ExifInterface

use of android.media.ExifInterface in project EnableHands by LeviWGG.

the class ImageUtils method getRotateDegree.

/**
 * Return the rotated degree.
 *
 * @param filePath The path of file.
 * @return the rotated degree
 */
public static int getRotateDegree(final String filePath) {
    try {
        ExifInterface exifInterface = new ExifInterface(filePath);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        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;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) Paint(android.graphics.Paint)

Example 22 with ExifInterface

use of android.media.ExifInterface in project android-mdm-agent by flyve-mdm.

the class Helpers method modifyOrientation.

/**
 * Modify the orientation according the rotation selected
 * @param bitmap
 * @param imageAbsolutePath the path to the image
 * @return Bitmap the modificated image
 */
public static Bitmap modifyOrientation(Bitmap bitmap, String imageAbsolutePath) throws IOException {
    ExifInterface ei = new ExifInterface(imageAbsolutePath);
    int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    switch(orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return rotate(bitmap, 90);
        case ExifInterface.ORIENTATION_ROTATE_180:
            return rotate(bitmap, 180);
        case ExifInterface.ORIENTATION_ROTATE_270:
            return rotate(bitmap, 270);
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            return flip(bitmap, true, false);
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            return flip(bitmap, false, true);
        default:
            return bitmap;
    }
}
Also used : ExifInterface(android.media.ExifInterface)

Example 23 with ExifInterface

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

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

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

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

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

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)

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