Search in sources :

Example 6 with ExifInterface

use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.

the class SaveImage method getExifData.

public ExifInterface getExifData(Uri source) {
    ExifInterface exif = new ExifInterface();
    String mimeType = mContext.getContentResolver().getType(mSelectedImageUri);
    if (mimeType == null) {
        mimeType = ImageLoader.getMimeType(mSelectedImageUri);
    }
    if (ImageLoader.JPEG_MIME_TYPE.equals(mimeType)) {
        InputStream inStream = null;
        try {
            inStream = mContext.getContentResolver().openInputStream(source);
            exif.readExif(inStream);
        } catch (FileNotFoundException e) {
            Log.w(LOGTAG, "Cannot find file: " + source, e);
        } catch (IOException e) {
            Log.w(LOGTAG, "Cannot read exif for: " + source, e);
        } catch (NullPointerException e) {
            Log.w(LOGTAG, "Invalid exif data for: " + source, e);
        } finally {
            Utils.closeSilently(inStream);
        }
    }
    return exif;
}
Also used : InputStream(java.io.InputStream) ExifInterface(com.android.gallery3d.exif.ExifInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 7 with ExifInterface

use of com.android.gallery3d.exif.ExifInterface in project platform_frameworks_base by android.

the class WallpaperCropActivity method getRotationFromExifHelper.

private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
    ExifInterface ei = new ExifInterface();
    InputStream is = null;
    BufferedInputStream bis = null;
    try {
        if (path != null) {
            ei.readExif(path);
        } else if (uri != null) {
            is = context.getContentResolver().openInputStream(uri);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        } else {
            is = res.openRawResource(resId);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        }
        Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (ori != null) {
            return ExifInterface.getRotationForOrientationValue(ori.shortValue());
        }
    } catch (IOException e) {
        Log.w(LOGTAG, "Getting exif data failed", e);
    } catch (NullPointerException e) {
        // Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
        Log.w(LOGTAG, "Getting exif data failed", e);
    } finally {
        Utils.closeSilently(bis);
        Utils.closeSilently(is);
    }
    return 0;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException)

Example 8 with ExifInterface

use of com.android.gallery3d.exif.ExifInterface in project android_frameworks_base by DirtyUnicorns.

the class WallpaperCropActivity method getRotationFromExifHelper.

private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
    ExifInterface ei = new ExifInterface();
    InputStream is = null;
    BufferedInputStream bis = null;
    try {
        if (path != null) {
            ei.readExif(path);
        } else if (uri != null) {
            is = context.getContentResolver().openInputStream(uri);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        } else {
            is = res.openRawResource(resId);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        }
        Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (ori != null) {
            return ExifInterface.getRotationForOrientationValue(ori.shortValue());
        }
    } catch (IOException e) {
        Log.w(LOGTAG, "Getting exif data failed", e);
    } catch (NullPointerException e) {
        // Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
        Log.w(LOGTAG, "Getting exif data failed", e);
    } finally {
        Utils.closeSilently(bis);
        Utils.closeSilently(is);
    }
    return 0;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException)

Example 9 with ExifInterface

use of com.android.gallery3d.exif.ExifInterface in project android_frameworks_base by crdroidandroid.

the class WallpaperCropActivity method getRotationFromExifHelper.

private static int getRotationFromExifHelper(String path, Resources res, int resId, Context context, Uri uri) {
    ExifInterface ei = new ExifInterface();
    InputStream is = null;
    BufferedInputStream bis = null;
    try {
        if (path != null) {
            ei.readExif(path);
        } else if (uri != null) {
            is = context.getContentResolver().openInputStream(uri);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        } else {
            is = res.openRawResource(resId);
            bis = new BufferedInputStream(is);
            ei.readExif(bis);
        }
        Integer ori = ei.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (ori != null) {
            return ExifInterface.getRotationForOrientationValue(ori.shortValue());
        }
    } catch (IOException e) {
        Log.w(LOGTAG, "Getting exif data failed", e);
    } catch (NullPointerException e) {
        // Sometimes the ExifInterface has an internal NPE if Exif data isn't valid
        Log.w(LOGTAG, "Getting exif data failed", e);
    } finally {
        Utils.closeSilently(bis);
        Utils.closeSilently(is);
    }
    return 0;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException)

Example 10 with ExifInterface

use of com.android.gallery3d.exif.ExifInterface in project android_packages_apps_Gallery2 by LineageOS.

the class ImageLoader method getMetadataOrientation.

/**
 * Returns the image's orientation flag.  Defaults to ORI_NORMAL if no valid
 * orientation was found.
 */
public static int getMetadataOrientation(Context context, Uri uri) {
    if (uri == null || context == null) {
        throw new IllegalArgumentException("bad argument to getOrientation");
    }
    // First try to find orientation data in Gallery's ContentProvider.
    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
        if (cursor != null && cursor.moveToNext()) {
            int ori = cursor.getInt(0);
            switch(ori) {
                case 90:
                    return ORI_ROTATE_90;
                case 270:
                    return ORI_ROTATE_270;
                case 180:
                    return ORI_ROTATE_180;
                default:
                    return ORI_NORMAL;
            }
        }
    } catch (SQLiteException e) {
    // Do nothing
    } catch (IllegalArgumentException e) {
    // Do nothing
    } catch (IllegalStateException e) {
    // Do nothing
    } finally {
        Utils.closeSilently(cursor);
    }
    ExifInterface exif = new ExifInterface();
    InputStream is = null;
    // Fall back to checking EXIF tags in file or input stream.
    try {
        if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
            String mimeType = getMimeType(uri);
            if (!JPEG_MIME_TYPE.equals(mimeType)) {
                return ORI_NORMAL;
            }
            String path = uri.getPath();
            exif.readExif(path);
        } else {
            is = context.getContentResolver().openInputStream(uri);
            exif.readExif(is);
        }
        return parseExif(exif);
    } catch (IOException e) {
        Log.w(LOGTAG, "Failed to read EXIF orientation", e);
    } catch (NullPointerException e) {
        Log.w(LOGTAG, "Invalid EXIF data", e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
            Log.w(LOGTAG, "Failed to close InputStream", e);
        }
    }
    return ORI_NORMAL;
}
Also used : InputStream(java.io.InputStream) ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) Paint(android.graphics.Paint)

Aggregations

ExifInterface (com.android.gallery3d.exif.ExifInterface)12 IOException (java.io.IOException)11 InputStream (java.io.InputStream)7 BufferedInputStream (java.io.BufferedInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Uri (android.net.Uri)3 ExifTag (com.android.gallery3d.exif.ExifTag)3 FileNotFoundException (java.io.FileNotFoundException)3 ContentValues (android.content.ContentValues)2 Paint (android.graphics.Paint)2 Cursor (android.database.Cursor)1 SQLiteException (android.database.sqlite.SQLiteException)1 Bitmap (android.graphics.Bitmap)1 FilterFusionRepresentation (com.android.gallery3d.filtershow.filters.FilterFusionRepresentation)1 CachingPipeline (com.android.gallery3d.filtershow.pipeline.CachingPipeline)1 File (java.io.File)1