2

I'm a newbie in Android. I'm trying to make an application with the photo capturing feature inside. The problem is the photo rotation is not right. If I take the photo in landscape mode, it will be good, but in portrait mode the photo rotation will be wrong. My question is: can I check whether the photo is taken in landscape/portrait mode? Because as I checked on the LogCat I can see the tag named "CameraEngine" and it says rotation: 0 or 90. It will be cool if I can get that kind of camera information by code.

kablu
  • 629
  • 1
  • 7
  • 26
zacess
  • 21
  • 1
  • 4
  • do you want to know just after you capture the photo from camera, or while you pick that image from gallery? – sarabhai05 Oct 09 '12 at 06:55

3 Answers3

5

You can compare image width and height:

Bitmap bmp = your photo;

if(bmp.getWidth() > bmp.getHeight())
{
   // landscape
}else
{
   // portrait
}
Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
1

You cannot check in Android if the photo was taken specially with PhoneGape 2.9 and beyond.

Because you have to extract this information from EXIF property stored in the taken photo and android doesn't even write out the orientation to this property.

you can refer to this reply to the question bellow for more information : canvas drawImage() with photos taken on iphone in landscape are rotated

Community
  • 1
  • 1
ghost rider3
  • 448
  • 1
  • 5
  • 17
0

This should do what you need. It returns the orientation as an angle (0/90/180/270):

private int getOrientation(Uri aUri, ContentResolver aRslv) {
    Cursor _cursor = aRslv.query(aUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
            null, null, null);

    if (_cursor != null) {
        try {

            if (_cursor.moveToFirst()) {
                return _cursor.getInt(0);
            } else {
                return -1;
            }
        } finally {
            _cursor.close();
        }
    } else {
        return 0;
    }
}
Stevie
  • 7,957
  • 3
  • 30
  • 29
  • thank you for your answer. I tried to call it inside the onActivityResult, but the result's always returned 0. Did I do in the right way? please help – zacess Jul 17 '12 at 08:39
  • Are you getting a non-null cursor back from the ContentResolver? – Stevie Jul 17 '12 at 14:31
  • Yep, I got the cursor like this: "android.content.ContentResolver$CursorWrapperInner@405273f0". I also tried to print out the _cursor.getInt(0), it always returns 0. – zacess Jul 18 '12 at 08:07