Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileProvider Uri not providing Orientation details for Exif #44

Open
Code-N-K opened this issue Feb 20, 2018 · 1 comment
Open

FileProvider Uri not providing Orientation details for Exif #44

Code-N-K opened this issue Feb 20, 2018 · 1 comment

Comments

@Code-N-K
Copy link

Code-N-K commented Feb 20, 2018

@Mariovc - // After using URI from FileProvider ExifInterface is not providing orientation details when we ftech image from camera i have tested it in api 14 to api 24, the code works for Android M only.

`private static int getRotationFromCamera(Context context, Uri imageFile)
{
int rotate = 0;
try
{
context.getContentResolver().notifyChange(imageFile, null);

       // URI from FileProvider Not providing ORIENTATION details  for ExifInterface for api 14 to api 24

       ExifInterface exif = new ExifInterface(imageFile.getPath());   

        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);

        switch (orientation)
        {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
            default:
                rotate = 0;
                break;
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return rotate;
}`
@Code-N-K
Copy link
Author

Code-N-K commented Feb 20, 2018

@Mariovc Solution for Exif : as per android documentation

https://android-developers.googleblog.com/2016/12/introducing-the-exifinterface-support-library.html

Use import android.support.media.ExifInterface;

  1. Change in gradle build for : implementation "com.android.support:exifinterface:${libs.supportVersion}"
  2. Now import android.support.media.ExifInterface; in ImageRotator

and update the method

`private static int getRotationFromCamera(Context context, Uri imageFile)
{
int rotate = 0;

    InputStream in = null;

    try
    {
        context.getContentResolver().notifyChange(imageFile, null);

        in = context.getContentResolver().openInputStream(imageFile);

        ExifInterface exif = new ExifInterface(in); //imageFile.getPath());

        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);

        switch (orientation)
        {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
            default:
                rotate = 0;
                break;
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        if (in != null)
        {
            try
            {
                in.close();
            }
            catch (IOException ignored)
            {

            }
        }
    }

    return rotate;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant