简体   繁体   中英

Image orientation always returns zero in Samsung S series devices

I have created an application which uses the camera intent to capture photographs. The photographs are being captured fine and saved to respective folders. The issue is that only on Samsung S Series devices, the images ate always in Portrait mode, even if the image is captured in landscape mode. Due to this issue, I have tried to get the orientation of the captured images and then change them to my requirements accordingly, but the orientation always returns zero.

I am trying to use this method:

public static int getRotation(Context context,Uri selectedImage) {
    int rotation =0;
    ContentResolver content = context.getContentResolver();


    Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { "orientation", "date_added" },null, null,"date_added desc");

    if (mediaCursor != null && mediaCursor.getCount() !=0 ) {
        while(mediaCursor.moveToNext()){
            rotation = mediaCursor.getInt(0);
            break;
        }
    }
    mediaCursor.close();
    return rotation;
}

The method always returns 0 no matter what is the orientation of the image. Where am I going wrong? What is to be done to address the issue?

Samsung likes to break stuff. I have a similar experience before.

But the camera intent should have saved the orientation info as Exif in the jpg file.

As you are using camera Intent, you should have the File Uri. Then you can use ExifInterface to extra the rotation directly from the file.

http://developer.android.com/reference/android/media/ExifInterface.html

Sample code

ExifInterface exif = new ExifInterface(file);
int oridentation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
       //do what you want
       break;
    case ExifInterface.ORIENTATION_ROTATE_180:
       //do what you want
       break;
    ....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM