Android Question Retrieve image from MYSQL database

eng.khalidvb

Member
Licensed User
Longtime User
Hi,

I Have an issue to retrieve image from MYSQL database. please help. see code below

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
Dim listview1 As ListView
Dim imageload ="Imageload" As String

    Private ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("test")
'listview1.SetLayout(0,0,100%x,100%y)

ExecuteRemoteQuery("SELECT logo FROM MS_Markets_tb",imageload)


End Sub


Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://khalidvb.com/Android_Conn/MobileConn.php", Query)
   
End Sub

Sub JobDone(Job As HttpJob)
   
ProgressDialogHide
   
    If Job.Success  Then
    Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
       
    Select Job.JobName
                   
                     Case imageload
                        
                       
               Dim UserDetails As List
                UserDetails = parser.NextArray 'returns a list with maps
                For i = 0 To UserDetails.Size - 1
                    Dim X As Map
                    X = UserDetails.Get(i)
                   

Dim b() As Byte  
Dim bmp As Bitmap
Dim s As StringUtils
Dim ix As InputStream
b =s.DecodeBase64(x.Get("logo"))
ix.InitializeFromBytesArray(b,0,b.Length)
bmp.Initialize2(ix)
ix.Close



                    listview1.AddTwoLinesAndBitmap("LULU","LuLu Hypermarket", bmp)
                   
                    Next
                    
                  
                   
                   
    End Select
    Else
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
   
    End If
   
    Job.Release
   
   
End Sub
 

Anser

Well-Known Member
Licensed User
Longtime User
Try this.

B4X:
Dim ImageData As String
ImageData = oRecord.Get("Your_Image_Column_Name")
       
Dim ImageBytes() As Byte
Dim oBitmap As Bitmap
Dim su As StringUtils

ImageBytes = su.DecodeBase64(ImageData)
Dim oInputStream As InputStream
oInputStream.InitializeFromBytesArray(ImageBytes,0,ImageBytes.Length)
oBitmap.Initialize2(oInputStream)
oInputStream.Close

Dim oImgView As ImageView
oImgView.Initialize("")
oImgView.Bitmap = oBitmap

Regards
Anser
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…