Search in sources :

Example 1 with ExifInterface

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

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

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

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

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

the class ImageLoader method getExif.

public static List<ExifTag> getExif(Context context, Uri uri) {
    String path = getLocalPathFromUri(context, uri);
    if (path != null) {
        Uri localUri = Uri.parse(path);
        String mimeType = getMimeType(localUri);
        if (!JPEG_MIME_TYPE.equals(mimeType)) {
            return null;
        }
        try {
            ExifInterface exif = new ExifInterface();
            exif.readExif(path);
            List<ExifTag> taglist = exif.getAllTags();
            return taglist;
        } catch (IOException e) {
            Log.w(LOGTAG, "Failed to read EXIF tags", e);
        } catch (NullPointerException e) {
            Log.e(LOGTAG, "Failed to read EXIF tags", e);
        }
    }
    return null;
}
Also used : ExifTag(com.android.gallery3d.exif.ExifTag) ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException) Uri(android.net.Uri)

Example 4 with ExifInterface

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

the class LocalImage method rotate.

@Override
public void rotate(int degrees) {
    GalleryUtils.assertNotInRenderThread();
    Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
    ContentValues values = new ContentValues();
    int rotation = (this.rotation + degrees) % 360;
    if (rotation < 0)
        rotation += 360;
    if (mimeType.equalsIgnoreCase("image/jpeg")) {
        ExifInterface exifInterface = new ExifInterface();
        ExifTag tag = exifInterface.buildTag(ExifInterface.TAG_ORIENTATION, ExifInterface.getOrientationValueForRotation(rotation));
        if (tag != null) {
            exifInterface.setTag(tag);
            try {
                exifInterface.forceRewriteExif(filePath);
                fileSize = new File(filePath).length();
                values.put(Images.Media.SIZE, fileSize);
            } catch (FileNotFoundException e) {
                Log.w(TAG, "cannot find file to set exif: " + filePath);
            } catch (IOException e) {
                Log.w(TAG, "cannot set exif data: " + filePath);
            }
        } else {
            Log.w(TAG, "Could not build tag: " + ExifInterface.TAG_ORIENTATION);
        }
    }
    values.put(Images.Media.ORIENTATION, rotation);
    mApplication.getContentResolver().update(baseUri, values, "_id=?", new String[] { String.valueOf(id) });
}
Also used : ContentValues(android.content.ContentValues) ExifTag(com.android.gallery3d.exif.ExifTag) ExifInterface(com.android.gallery3d.exif.ExifInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File)

Example 5 with ExifInterface

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

the class Exif method getOrientation.

/**
 * Returns the degrees in clockwise. Values are 0, 90, 180, or 270.
 */
public static int getOrientation(InputStream is) {
    if (is == null) {
        return 0;
    }
    ExifInterface exif = new ExifInterface();
    try {
        exif.readExif(is);
        Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
        if (val == null) {
            return 0;
        } else {
            return ExifInterface.getRotationForOrientationValue(val.shortValue());
        }
    } catch (IOException e) {
        Log.w(TAG, "Failed to read EXIF orientation", e);
        return 0;
    }
}
Also used : ExifInterface(com.android.gallery3d.exif.ExifInterface) IOException(java.io.IOException)

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