Android Question LoadBitmapResize, LoadBitmap are rotating images

MrKim

Well-Known Member
Licensed User
Longtime User
What am I missing??

Here is my code

B4X:
                II.SetLayout(0, 0, PH, PW)
                II.Gravity = Gravity.FILL
                II.Bitmap = LoadBitmapResize(Dir, FileName, PW, PH, True)
                P.AddView(II, 0, 0, PW, PH)

This is how it looks when viewed with Photos.

upload_2019-11-23_7-13-57.png


And this is how it looks when loaded into an image view. Notice I have reversed Height and width on some of these.
upload_2019-11-23_7-12-55.png


I have tried changing the gravity and reversing the height and width in any number of combinations to no avail.

here are the specs on the picture.
upload_2019-11-23_7-19-34.png


It appears that the issue is with all pictures taken in portrait mode. Pictures taken in landscape mode load ok.
 

Attachments

  • upload_2019-11-23_7-20-41.png
    upload_2019-11-23_7-20-41.png
    95.1 KB · Views: 314
  • upload_2019-11-23_7-21-21.png
    upload_2019-11-23_7-21-21.png
    104.1 KB · Views: 324

sorex

Expert
Licensed User
Longtime User
I believe that android's default image handling doesn't take the rotation info into account that is sometimes added to the image header (by cameras?).
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
ImageView displays a Bitmap and Bitmaps don't carry any orientation data as LoadBitmap seems to ignore it. You probably need to rotate the Bitmap of the image according to the EXIF orientation data in the original jpg image file. You should be able to get this using this library

https://www.b4x.com/android/forum/threads/android-support-exifinterface.74629/#content

Png files don't usually carry orientation information.
You would think that the first number would be x and the second y (or vice versa)? I mean ContnetChooser knows which way the picture is oriented. Where does it get its information?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
From ContentChooser documentation https://www.b4x.com/android/help/phone.html#contentchooser
The ContentChooser object allows the user to select a specific type of content using other installed applications.
For example the user can use the internal Gallery application to select an image.
ContentChooser doesn't know, it is the application you choose that does.

In my experience cameras always save the image in the same orientation relative to the camera. The camera software then uses the device rotation sensor to tag the orientation as landscape or portrait in the EXIF data of the image. This lets the image decoder software orient the image correctly for display.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
From ContentChooser documentation https://www.b4x.com/android/help/phone.html#contentchooser
ContentChooser doesn't know, it is the application you choose that does.

In my experience cameras always save the image in the same orientation relative to the camera. The camera software then uses the device rotation sensor to tag the orientation as landscape or portrait in the EXIF data of the image. This lets the image decoder software orient the image correctly for display.
I'm just trying to understand here. If ContentChooser doesn't know then why are images always displayed correctly? Some have X>y and some have y>x but content chooser always displays them oriented correctly. And in a view that is sized correctly? This just doesn't make sense to me.
 
Upvote 0
Top