-1

Usually, the image that have width > height is landscape and the width < height is portrait.

But for some reason, my Samsung Galaxy S6's image's W:H (taken by default camera app) is always landscape even though it's portrait.

Both landscape and portrait image's info shows 5312 x 2988. The portrait should be 2988 x 5312 but it's not, it shows 5312 x 2988 too.

That's why the input into my codes always recognizes the image as landscape.

There must be some other way to check it, because the portrait image is displayed correctly in gallery. If they use the W:H of the image then all images should've been displayed as landscaped.

Is there any other info within the image that can be used? Thank you for your time.

Tran Hoai Nam
  • 1,273
  • 2
  • 18
  • 35

2 Answers2

0

Images always taken in landscape mode on almost every device hence there size for both if you see them in landscape and portrait will be same.

You can check device orientation by following code:

 getResources().getConfiguration().orientation

and get a callback whenever orientation changes in

onConfighanges(Configuration newConfig)

see this link

Community
  • 1
  • 1
Najeeb Idrees
  • 453
  • 6
  • 15
  • Thank you! But only a few devices show the same size, and it doesn't matter if the image is taken while the phone is in portrait or landscape mode. It's about the size of the image not the current state of the phone (like you can take the picture in portrait mode, but then use the code that import the image in landscape mode - the picture must be detected as portrait, ` getResources().getConfiguration().orientation` just get the state of the phone). – Tran Hoai Nam Nov 25 '16 at 12:54
0

I found a workaround for the problem. This may not work 100% but maybe it'll helps.

I ended up using ExifInterface to check for the ExifInterface.TAG_ORIENTATION like this:

ExifInterface exifi = new ExifInterface(originalAvatarPath.getPath());
                int ori = Integer.parseInt(exifi.getAttribute(ExifInterface.TAG_ORIENTATION));

Then compare ori if it equals with value like ExifInterface.ORIENTATION_ROTATE_180 or ExifInterface.ORIENTATION_ROTATE_90 which is described in here

Not all image will contains the Exif info, but it works for me.

Hope it helps.

Tran Hoai Nam
  • 1,273
  • 2
  • 18
  • 35