I have made a sample on displaying the image file in the database and saved it as Blob data type. But the image file in the db doesnt show the image on my ImageView1.
Here's my code:
Here's my code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
If File.Exists(File.DirInternal,"dbImage.db") = False Then
File.Copy(File.DirAssets,"dbImage.db",File.DirInternal,"dbImage.db")
End If
If sql1.IsInitialized = False Then
sql1.Initialize(File.DirInternal, "dbImage.db", False)
End If
Dim Cursor1 As Cursor
cursor1 = sql1.ExecQuery2("SELECT * FROM tblImage WHERE imgField = ?", Array As String("book3"))
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim Buffer() As Byte 'declare an empty byte array
Buffer = Cursor1.GetBlob("imgField")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
ImageView1.SetBackgroundImage(Bitmap1)
Next
End Sub