Android Question Check if a gallery image is portrait or landscape.

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
In my appl I check the height and width of the images from gallery.

So I know if image is portrait or landscape.
However, this does not always work. Some devices take pictures in "portrait" and the width values in the details appears bigger than height.

What am I doing wrong?

Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Basically I get an image from gallery to edit. If the image has w<h then I present it to user as portrait. If the image has w> h then I present it to user as landscape. This does not always work

Problem:

The Zenfone 2 device takes photos from the standard photo app and saves the details as w>h. Always. For portrait and landscape too. This also seems to happen with the galaxy S6.

Curiously Zenfone saves the details of the image always as w>h however it shows perfectly in the gallery app.

I go to try ExifData. But imagens details show ORIENTATION always 0.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Usally, before answer to someone, I see how much he's old (as member :)) and "you are 3 years old"; so my answer below could be superfluous.

If you want to know Width and Height of an image before to load it, I can understand your problem (and ExifData can solve this problem but not with png file, for example).

Otherwise, you should simply load the image file in a bitmap variable, check its orientation, and act (show it) accordingly.

B4X:
    Dim bmp As Bitmap = LoadBitmap(File.DirAssets, "YourImage.png")
Dim IsLandscape = (bmp.Width > bmp.Height)
If IsLandscape Then
    ' Landscape.
    ' Resize the container (ImageView?) for a landscape photo
    ' and pass bmp to it.
Else
    ' Portrait.
     ' Resize the container (ImageView?) for a portrait photo
    ' and pass bmp to it.
End If
 
Last edited:
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Usally, before answer to someone, I see how much he's old (as member :)) and "you are 3 years old";

No problem.
Wow! 3 years and I still have so much to learn.

Today I found this a blog called adrian's blog:

"Rotate images according to EXIF info"

"Some digital cameras are saving the snapshots as they come from the digital sensor. This is not always the right orientation, as it depends on how you position the camera." Luckily, the cameras are also saving the information in EXIF attributes. "

There are some pictures showing the issue.
There is also a java code to work around the problem.

I thought it best not to put an external link here. But, maybe you can search the blog on google. Easy.

At least now I understand the problem.

The problem is how to do this in B4A.
 
Upvote 0
Top