Android Question save image in SQL

catyinwong

Active Member
Licensed User
Longtime User
I am have tried converting files into byte by FILE.READBYTE and insert into SQL and then select the data and convert back to a file by FILE.WRITEBYTE. But it turns out that the data is not stored probably somehow. The size of the inserted file is 920564 and the read file is 12 @@

I am wondering if the wrong column type I using (now I m using BLOB) or something else goes wrong. Any suggestions?
 

toby

Well-Known Member
Licensed User
Longtime User
For reading blob

B4X:
Sub ReadBlob
    Dim Cursor1 As Cursor = SQL1.ExecQuery2("SELECT image FROM table2 WHERE name = ?", Array As String("smiley"))
    Cursor1.Position = 0
    Dim Buffer() As Byte = Cursor1.GetBlob("image")
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize2(InputStream1)
    InputStream1.Close
    Activity.SetBackgroundImage(Bitmap1)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…