Android Question How do I save an image stored in a Binary data field in SQL to a Webview control?

tstmartin

New Member
Licensed User
I have jpg images stored in a Binary field in a SQL Server database and I would like to display the images in a WebView control. I can retrieve other fields and display them however I am not sure how to retrieve a Binary field. I've searched but can't find an example.

If you can point me in the right direction that would be great.

Thanks in advance for your help.
 

Peter Simpson

Expert
Licensed User
I presume that you(or whoever) are first converting the image to a byte array before storing the image into the binary field, thus you can just reverse the process to get the image back?

If the image is stored as a byte array then this should work for you. Just manipulate the following code to do what you want.

B4X:
Dim buffer() As Byte
'buffer contains the image data

Dim ArrayIn As InputStream
    ArrayIn.InitializeFromBytesArray(buffer, 0, buffer.Length)
Dim Bmp As Bitmap
    Bmp.Initialize2(ArrayIn)
ArrayIn.Close

How are you inserting the images into the database in the first place?
 
Last edited:
Upvote 0
Top