Android Question conversione array byte -> stringa -> byte

ninateam

New Member
Hi, I've come across two lines of code that I can't get to work, even using an alternate code.

The idea was to store small images in a Postgresql database in string format. Actually this I already do from Xojo.


B4X:
Private Sub decodButton_Click
    Dim myBitmap As B4XBitmap = ImageView1.GetBitmap
    Dim m1b(), m2b() As Byte
    Dim myStringa  As String
    Dim conv As ByteConverter

    m1b = ImageToBytes(myBitmap)
    
    myStringa    = BytesToString(m1b, 0, m1b.Length, "utf16")
    m2b =   myStringa.GetBytes("utf16") 'convert to bytes
    If m1b<>m2b Then
        xui.MsgboxAsync("First bad conversion","!!!!!!!!!!")
    End If
    
    myStringa = conv.StringFromBytes (m1b,"UTF16")
    m2b = conv.StringToBytes (myStringa,"UTF16")
    If m1b<>m2b Then
        xui.MsgboxAsync("Second bad conversion","!!!!!!!!!!")
    End If
    
    myBitmap = BytesToImage(m1b) ' OK only for m1b
    toImageView.SetBitmap(myBitmap) 
        
End Sub


In m1b I insert the Byte array from an imageview.
I try to convert this m1b into a string in the myStringa variable and then convert it back into a byte array in m2b.
At this point I would expect m1b and m2b to be the same but both ways are different.

Where am I doing wrong? Can anyone recommend me a solution?
 
Last edited by a moderator:

ninateam

New Member
Tank you very much !
but is it true that m1b and m2b result different ( if m1b <>m2b then IS true!) ?
In every case now I can see m2b in my imageView when I do :
myBitmap = BytesToImage(m2b)
toImageView.SetBitmap(myBitmap)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…