Android Question Imageview.bitmap 2 Blob and vice versa

Guenter Becker

Member
Licensed User
I looked through the posts (for example SQL Tutorial) and even find only statements pointing to transfer a bitmap file into a byte array (Dim Buffer() As Byte = File.ReadBytes(File.DirAssets, "smiley.gif")). But this is not I am looking for.

1st I need an b4x/b4a example how to transfer layout imageview.bitmap -> byte array -> byte array insert into sqlite database blob field and
2nd the way back from the blob field -> byte array -> imageview.bitmap.

Can anyone help me?
Thank you in advance Guenter
 

mangojack

Well-Known Member
Licensed User
from an old project ...

B4X:
'get ImageView bitmap and write to database
    Dim bmp As Bitmap = imvImage.Bitmap
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    bmp.WriteToStream(OutputStream1, 90, "JPEG")
    Dim Buffer() As Byte = OutputStream1.ToBytesArray
    oSQL.ExecNonQuery2("INSERT INTO tbl_Name VALUES (NULL, ?, ?)", Array As Object(title, Buffer ))


'get database image/blob and load to bitmap
    Dim Buffer() As Byte  = res.GetBlob("Image") 'res = ResultSet
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim Bmp As Bitmap
    Bmp.Initialize2(InputStream1)
    InputStream1.Close
    imvImage.Bitmap = Bmp
 
Last edited:
Top