Android Question Simple Media Manager how to read a stream image

i have this statement to read images from flies to local disk.
Read image from file:
MediaManager.SetMediaFromFile(xB,"c:\icone\",nomefile,"image/png", Null)

I would like to read images from a stream coming from a blob image of an mssql db that I read with this code

Read image from database mssql:
Dim Buffer() As Byte 'declare an empty byte array
    Dim InputStream1 As InputStream
    Buffer = Cursor1.GetBlob("immagineblob")
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
'TEST OK  
    Dim img As Image
    img.Initialize2(InputStream1)
    ImageView1.SetImage (img)
    InputStream1.Close

With SMM is it possible to read an image coming from an array or a database instead of a file or a url?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can AddLocalMedia to add bitmaps directly to the media cache.
B4X:
SMM.AddLocalMedia("image key", img, "image/*")
Note that those images will not be removed from the cache so it will not work if the number of images is large.
The other option, which might be simpler and better, is to copy the bytes to temporary files (File.WriteBytes).
 
Upvote 0
Top