Android Question Image rotation problem with native camera

Douglas Farias

Expert
Licensed User
Longtime User
hi i have some questions about orientation in native camera
1° i m using the native camera to take photos - ITS OK

2° i save this photo on my device - ITS OK
look here >> http://clickfight.com.br/mostra/1.jpg

3° i send this photo for any php server inclusive anywhere softwhere forum - PROBLEM
when i send this photo to any server apache i have orientation - rotation problem
look here the 1.jpg uploaded >> http://clickfight.com.br/mostra/2.jpg

inclusive here on the forum! try click at addimage and add http://clickfight.com.br/mostra/1.jpg in the post it go rotate why this? i m crazy here

i m using this code to start the camera by @NJDude

B4X:
Sub OpenCam(Directory As String, PictureName As String)

    Dim i As Intent

    i.Initialize("android.media.action.IMAGE_CAPTURE", "")
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName)))
        
    StartActivity(i)
        
End Sub

Sub ParseUri(FileName As String) As Object

    Dim r As Reflector

    Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(FileName), Array As String("java.lang.String"))

End Sub

AND
OpenCam(File.DirDefaultexternal, "MyPicture.jpg")

when i save the image is normal no problem i tested take a picture and look this on my device
is normal like this http://clickfight.com.br/mostra/1.jpg

but i upload this image to any server and it make a rotation

http://clickfight.com.br/mostra/2.jpg

can someone help me with this pls ? i realy dont know fix at this time
i think need set a orientation when open the camere
open the camera set only portrait but how *-*


*this problem is only with galaxy S3 AND galaxy start trios the MOTO G dont have this problem save the photo on portrait and later uploaded stay on portrait dont change!


here a similar problem but not in b4a

http://stackoverflow.com/questions/6069122/camera-orientation-issue-in-android
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
@Erel how can i know the rotation?

msg.Append("Orientação : ").Append(exif.getAttribute(exif.TAG_ORIENTATION)).Append(CRLF)

on the galaxy devices this return 6 and image is saved on landscape


on another devices is 0 or 1 and is saved on portrait < what i want ;)


i tested on galaxy = 6
moto g = 0




can help me how to rotate landscape for portrait?
 
Last edited:
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
ty i m fixed with this code
B4X:
    Dim bmp As Bitmap
    Dim rbmp As RSImageProcessing
    Dim casa As String
    Dim exif As ExifData
   
    rbmp.Initialize
    bmp.Initialize(FP, "1.jpg")
    exif.Initialize(FP, "1.jpg")
    casa =  exif.getAttribute(exif.TAG_ORIENTATION)
    If casa = 6 Then
    exif.setAttribute(exif.TAG_ORIENTATION, 1)
    exif.saveAttributes
    If bmp.width>bmp.height Then     
    bmp = rbmp.Rotate(bmp, 90)
    rbmp.writeBitmapToFile(bmp,FP ,"1.jpg", 100 )
    End If
    End If
 
Upvote 0
Top