After several attempts and tests I found my own solution using the accelerometer. Moreover, given that I was "the only one" to implement this solution (on the forum I have not found anything like this except for the part of the code relating to the exif data) plus the rotation of the photo always in the right direction, I would suggest adding all the official library or in some way to stand out. Can return certainly useful to someone else..
Sub FotocameraLib_PictureTaken (Data() As Byte)
...
...
...
ModificaOrientamento(PercorsoFile, NomeFile, DatiSensore)
End sub
Sub Accellerometro_AccelerometerChanged (X As Float, Y As Float, Z As Float)
'Log(DatiSensore)
DatiSensore = Round(ATan2D(Y, X))
End Sub
Public Sub ModificaOrientamento(Dir As String, Filename As String, DatiSensore As Double)
Dim bm As Bitmap
bm=LoadBitmapSample(Dir, Filename, 100%x, 100%y)
Dim bm2 As BitmapExtended
Dim exifdata1 As ExifData
bm2.Initialize("")
Try
exifdata1.Initialize(Dir, Filename)
'
http://sylvana.net/jpegcrop/exif_orientation.html
' 1) transform="";;
' 2) transform="-flip horizontal";;
' 3) transform="-rotate 180";;
' 4) transform="-flip vertical";;
' 5) transform="-transpose";;
' 6) transform="-rotate 90";;
' 7) transform="-transverse";;
' 8) transform="-rotate 270";;
If DatiSensore >= -20 AND DatiSensore <= 20 Then
exifdata1.setAttribute(exifdata1.TAG_ORIENTATION, 1)
exifdata1.saveAttributes
Else If DatiSensore >= 75 AND DatiSensore <= 100 Then
exifdata1.setAttribute(exifdata1.TAG_ORIENTATION, 1)
exifdata1.saveAttributes
bm = bm2.rotateBitmap(bm, 90)
Else If (DatiSensore >= 165 AND DatiSensore <= 180) OR (DatiSensore >= -180 AND DatiSensore <= -170) Then
exifdata1.setAttribute(exifdata1.TAG_ORIENTATION, 1)
exifdata1.saveAttributes
bm = bm2.rotateBitmap(bm, 180)
End If
' Riscrivo l'immagine con il giusto orientamento
Dim Out As OutputStream
Out = File.OpenOutput(Dir, "Temp2.jpg", False)
bm.WriteToStream(Out, 100, "JPEG")
Out.Close
Catch
Msgbox(LastException, "Errore Immagine")
End Try
End Sub