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