B4J Question [ABMaterial] get blob data and show it in ABMimage

jayel

Active Member
Licensed User
Longtime User
Hello,

I want to get BLOB images from a database and show it in a ABMimage.
I suppose, I have to save the blob as a file and then put the image in ABMImage as so :
B4X:
Sub ReadBlob(SQL As SQL,Query As String) As List
    Dim Cursor1 As ResultSet
    Dim myreturn As List
    'Using ExecQuery2 is safer as it escapes special characters automatically.
    'In this case it doesn't really matter.
    Dim dir As String = "../images/"
    Dim filename As String
    Dim machid As Int
    Dim produktid As Int
    Cursor1 = SQL.ExecQuery(Query)
    Do While Cursor1.NextRow
        machid = Cursor1.GetInt("machnr")
        produktid = Cursor1.GetInt("produktid")
        filename = machid & "_" & produktid & ".jpg"
        Dim Buffer() As Byte 'declare an empty byte array
        Buffer = Cursor1.GetBlob("afbeelding")
        Dim out As OutputStream = File.OpenOutput(dir, filename, False)
        out.WriteBytes(Buffer, 0, Buffer.Length)
        out.Close
        myreturn.Add(filename)
    Loop
'    Dim Bitmap1 As Image
'    Bitmap1.Initialize2(InputStream1)
'    InputStream1.Close
    'Activity.SetBackgroundImage(Bitmap1)
    Return myreturn
End Sub

I get following error
Is this the way I have to do it? Or are there other ways?

John
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…