Android Question Camera2 / CameraEX, there is only 1 orientation in the image

Daica

Active Member
Licensed User
I am currently using these 2 libraries:
1 - https://www.b4x.com/android/forum/t...tends-the-camera-library-functionality.23801/
2 - https://www.b4x.com/android/forum/threads/camera2-still-images-and-videos.83920/

When I take a picture and record the orientation through the function RotateJpegIfNeeded, the orientation is always "6" no matter what.
So when the function runs, the picture only has 1 correct orientation.

B4X:
Public Sub RotateJpegIfNeeded (bmp As B4XBitmap, Data() As Byte) As B4XBitmap
    Dim p As Phone
    If p.SdkVersion >= 24 Then
        Log("Phone SDK Ver: " & p.SdkVersion)
        Dim ExifInterface As JavaObject
        Dim in As InputStream
        in.InitializeFromBytesArray(Data, 0, Data.Length)
        ExifInterface.InitializeNewInstance("android.media.ExifInterface", Array(in))
        Dim orientation As Int = ExifInterface.RunMethod("getAttribute", Array("Orientation"))
        Log("Picture Orientation: " & orientation) 'This always returns 6
        Select orientation
            Case 3  '180
                bmp = bmp.Rotate(180)
            Case 6 '90
                bmp = bmp.Rotate(90)
            Case 8 '270
                bmp = bmp.Rotate(270)
        End Select
        in.Close
    End If
    Return bmp
End Sub

Anyone else has the same problem? Is it the phone? or Am I doing something wrong?
The phone's SDK Ver is 29
The camera's supported hardware is: LEVEL_3
 

agraham

Expert
Licensed User
Longtime User
It looks like you are instantiating the ExifInterface from a byte array. What is the byte array supposed to represent? I wouldn't expect a byte array to have associated EXIF information.

You will could try looking look at the jpg image file EXIF data with this library JpegUtils library gives access to Exif data | B4X Programming Forum
 
Upvote 0
Top