Through some examples here of the forum I was able to read a table with a blob field (image), insert in an internal sqlite database and display in an activity using the ImageView.
But I thought the code was a bit "confused / complex" and was in doubt if the way I'm doing is correct or is there another simpler / better.
Made as follows (sample):
The major questions:
a) in the "jobdone": it is necessary to keep the "Dim dados(4) As Object" inside the loop?
b) in the "jobdone": I have problems of out of memory if there are many records?
c) in the "jobdone": read/write blob(text only) is the same when read/write a blob(image)?
d) displaying the image: the only way is to use a sequence:
getBlob => Buffer () => InputStream => BitMap => ImageView ?
e) displaying the image: Can I use dbUtils to simplify?
Thanks!
But I thought the code was a bit "confused / complex" and was in doubt if the way I'm doing is correct or is there another simpler / better.
Made as follows (sample):
Table name: COMPLEMENTOS and structure:
IDCOMPLEMENTO, INTEGER
DESCRICAO, TEXT
OBS, BLOB
FOTO, BLOB
1) in the procedure "jobdone":
B4X:
For Each records() As Object in Result.Rows
Dim dados(4) As Object
Dados(0) = records(0)
Dados(1) = records(1)
Dim Buffer() As Byte
Buffer = records(2)
dados(2) = Buffer
Dim Buffer() As Byte
Buffer = records(3)
Dados(3) = Buffer
SQL1.ExecNonQuery2("INSERT INTO COMPLEMENTOS (IDCOMPLEMENTO,DESCRICAO,OBS,FOTO) VALUES (?,?,?,?)", Dados)
Next
2) View the image in any activity:
B4X:
(...)
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT FOTO FROM COMPLEMENTOS WHERE IDCOMPLEMENTO = "&nID)
If Cursor1.RowCount>0 Then
Cursor1.Position = 0
Dim Buffer() As Byte
Buffer = Cursor1.GetBlob("Foto")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
ImageView1.Bitmap = Bitmap1
End If
Cursor1.Close
(...)
The major questions:
a) in the "jobdone": it is necessary to keep the "Dim dados(4) As Object" inside the loop?
b) in the "jobdone": I have problems of out of memory if there are many records?
c) in the "jobdone": read/write blob(text only) is the same when read/write a blob(image)?
d) displaying the image: the only way is to use a sequence:
getBlob => Buffer () => InputStream => BitMap => ImageView ?
e) displaying the image: Can I use dbUtils to simplify?
Thanks!
Last edited: