Italian Esecuzione di una fotografia e sua visualizzazione

AlpVir

Well-Known Member
Licensed User
Longtime User
Con le seguenti istruzioni registro in un campo BLOB di un database sqlite l'immagine fornita dalla fotocamera.
B4X:
Dim strSQL     As String
Dim Dt        As Long
strSQL="INSERT INTO TabFoto (DataFoto,NumeroFoto,ImmagineFoto) VALUES(?,?,?)"
Try
    DateTime.DateFormat = "yyyyMMdd"
    Dt=DateTime.date(DateTime.Now)
    db.ExecNonQuery2(strSQL ,Array As Object(Dt,NumFoto,Data))
Catch
     Log(LastException.Message)
End Try

Che nel campo BLOB ci sia un'immagine è certo perchè posso visualizzarla in un tempo successivo con le istruzioni
B4X:
Dim bytes() As Byte
bytes = rsFoto.GetBlob( "ImmagineFoto")
ImageView1.Bitmap = BytesToImage(bytes)
Il guaio è che l'immagine è ruotata di 90 gradi ed è molto molto ingrandita.
Come fare a visualizzare l'immmagine in tutta la sua interezza (100%x e 100%y in un ImageView o altro view) e nel suo originario orientamento (sempre verticale comunque) ?
Grazie per l'attenzione.
 

MarcoRome

Expert
Licensed User
Longtime User
Un alcuni dispositivi l'immagine ritorna un jpeg con la stessa ruotata (exif header).
Se al posto di Imageview utilizzi SMM penserà lui stesso ad inserirla correttamente.

 

Sagenut

Expert
Licensed User
Longtime User

AlpVir

Well-Known Member
Licensed User
Longtime User
Stupefacente per me che ci siano smarthone che ruotano l'immagine di 90 gradi e altri che non lo fanno. Perchè poi non lo so.
Comunque ne possiedo 2, uno per qualità e credo di aver risolto il problema utilizzando la sub seguente :
B4X:
Private Sub RotateJpegIfNeeded (bmp As B4XBitmap, Data() As Byte) As B4XBitmap
    Dim p As Phone
    If p.SdkVersion >= 24 Then
        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("orientation=" & orientation)
        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
richiamata in questo modo
B4X:
Dim bytes()     As Byte
Dim rb             As Bitmap
bytes = rsFoto.GetBlob( "ImmagineFoto")
Dim b As Bitmap = BytesToImage(bytes)
rb=RotateJpegIfNeeded (b,bytes)
IV.Bitmap = rb.Resize(PanelFoto.width, PanelFoto.Height, True)
Spero proprio di aver risolto.
 
Top