Please a simple example to read a Blob field with image and upload it to an ImageView

desof

Well-Known Member
Licensed User
Longtime User
Please a simple example to read a Blob field with image from a MySQL database ycargarla the image in a ImageView.
I'm walking for hours through the forum and can not find the solution
 

dxxxyyyzzz

Member
Licensed User
Longtime User
Let's say that you have a table with two fields, name and image. Name is the picture name and image is the bloob field with picture.
Then you can try:

B4X:
Sub ReadBlob(ImageName As String)
           
   Dim Cursor1 As Cursor
   Dim Buffer() As Byte
   Dim IpSt As InputStream
   Dim Bitmap1 As Bitmap
   Cursor1 = SQL1.ExecQuery("SELECT * FROM table1 WHERE name = '" & ImageName & "' ;")
 
   For i = 0 To Cursor1.RowCount - 1
      Cursor1.Position = i
   Next
 
   Buffer = Cursor1.GetBlob("image")
   IpSt.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
   Bitmap1.Initialize2(IpSt)
   IpSt.Close
   ImageViewSQL.SetBackgroundImage(Bitmap1)
   
End sub

You'll probably need to adjust code to Your needs, and don't forget to Dim and initialize ImageView.
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Let's say that you have a table with two fields, name and image. Name is the picture name and image is the bloob field with picture.
Then you can try:

B4X:
Sub ReadBlob(ImageName As String)
           
   Dim Cursor1 As Cursor
   Dim Buffer() As Byte
   Dim IpSt As InputStream
   Dim Bitmap1 As Bitmap
   Cursor1 = SQL1.ExecQuery("SELECT * FROM table1 WHERE name = '" & ImageName & "' ;")
 
   For i = 0 To Cursor1.RowCount - 1
      Cursor1.Position = i
   Next
 
   Buffer = Cursor1.GetBlob("image")
   IpSt.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
   Bitmap1.Initialize2(IpSt)
   IpSt.Close
   ImageViewSQL.SetBackgroundImage(Bitmap1)
   
End sub

You'll probably need to adjust code to Your needs, and don't forget to Dim and initialize ImageView.


Please help a little more but I use to access this database


B4X:
'Cursor1 = SQL1.ExecQuery("SELECT * FROM table1 WHERE name = '" & ImageName & "' ;")
    Cursor1 =ExecuteRemoteQuery("SELECT * FROM LOGO WHERE NOMBRE ='" & ImageName & "' ;",IMAGEN_LOGO)
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Here's a small example.
Tested on the real device.

Hello

When compiling I get this error:


Parsing code. 0.00
Compiling code. 0.17
Compiling layouts code. 0.02
Generating R file. Error
AndroidManifest.xml:11: error: No resource identifier found for attribute 'hardwareAccelerated' in package 'android'
 
Upvote 0
Top