Search in sources :

Example 16 with ExifInterface

use of android.media.ExifInterface in project WordPress-Android by wordpress-mobile.

the class ImageUtils method getExifOrientation.

public static int getExifOrientation(String path) {
    ExifInterface exif;
    try {
        exif = new ExifInterface(path);
    } catch (IOException e) {
        AppLog.e(AppLog.T.UTILS, e);
        return 0;
    }
    int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
    switch(exifOrientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return 0;
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
    }
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 17 with ExifInterface

use of android.media.ExifInterface in project platform_frameworks_base by android.

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

use of android.media.ExifInterface in project JamsMusicPlayer by psaravan.

the class FileBitmapHunter method getFileExifRotation.

static int getFileExifRotation(Uri uri) throws IOException {
    ExifInterface exifInterface = new ExifInterface(uri.getPath());
    int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL);
    switch(orientation) {
        case ORIENTATION_ROTATE_90:
            return 90;
        case ORIENTATION_ROTATE_180:
            return 180;
        case ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
    }
}
Also used : ExifInterface(android.media.ExifInterface)

Example 19 with ExifInterface

use of android.media.ExifInterface in project RxImagePicker by qingmei2.

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

Example 20 with ExifInterface

use of android.media.ExifInterface in project RxImagePicker by qingmei2.

the class PhotoMetadataUtils method shouldRotate.

private static boolean shouldRotate(ContentResolver resolver, Uri uri) {
    ExifInterface exif;
    try {
        exif = ExifInterfaceCompat.newInstance(getPath(resolver, uri));
    } catch (IOException e) {
        Log.e(TAG, "could not read exif info of the image: " + uri);
        return false;
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
    return orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) Point(android.graphics.Point)

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