Android Question Acelerar carga de imágenes descargadas de una base de datos. Speed up loading of images downloaded from a database

Hackito

Member
Buenas, tengo una aplicación y está terminada; pero, cuanto más artículos se van cargando, la aplicación se va volviendo más lenta. La base de datos la tengo en un hosting y el peso de las imágenes sería de entre 50 a 500 kb, incluso implementé un código para reducir el tamaño antes de guardar. Y me preocupa que, teniendo tan pocos artículos (50), la aplicación ya se queda hasta 2 minutos descargando.
Este sería el código para descargar las imágenes y pasarla a un customlistview.

(Google Traductor para los amigos)
Hello, I have an application and it is finished; but, the more articles are loaded, the application becomes slower. I have the database on a hosting and the weight of the images would be between 50 to 500 kb, I even implemented a code to reduce the size before saving. And I'm worried that, having so few articles (50), the application takes up to 2 minutes to download.

This would be the code to download the images and pass it to a customlistview.


Imagen Blob a CustomListview:
vSQL1 = "SELECT IDARTICULO, NOMBRE, CODIGO, SECCION, RAMO, COSTO, TIPOIVA, STOCKMINIMO, PRECIO1, PRECIO2, STOCK, To_BASE64(FOTO) AS FOTO FROM TBARTICULOS WHERE ESTADO = 'ACTIVO' AND IDLOCAL = '" & vIDLOCAL &"' AND SECCION <> 'DEUDA' "
    LPT.Clear
    Try
        Dim PageServer As String = "http://www.yateestelamary.com.py/archiventas/datasend.php"
        PageServer = "http://www.yateestelamary.com.py/archiventas/datasend.php"

        Dim js As HttpJob
        js.Initialize("", Me)
        js.download2(PageServer, Array As String ("act", "CONSULTA","query",vSQL1))
                
        Wait For (js) JobDone(js As HttpJob)
        If js.Success Then
            Dim res As String
            res = js.GetString
            Dim parser As JSONParser
            parser.Initialize(res)
                        
            If res <> False Then
                Dim Tabla As List
                Tabla = parser.NextArray
                Dim Fila As Map
                
                For x = 0 To 4
                    img(x).Initialize("")
                Next
                
                For i=0 To Tabla.size-1
                    Fila =  Tabla.Get(i)
                    Dim vNombre As String = Fila.Get("NOMBRE")
                    Dim vValue As String = Fila.Get("IDARTICULO")
                    Dim vCantidad As String = Fila.Get("STOCK") & "/Min:"&Fila.Get("STOCKMINIMO") & Chr(10) & Chr(13) & "COSTO:" & formatter.Format(Fila.Get("COSTO")) & Chr(10) & Chr(13) & "PRECIO:" & formatter.Format(Fila.Get("PRECIO1")) & "/" & formatter.Format(Fila.Get("PRECIO2"))
                    Dim encondedString As String = Fila.Get("FOTO")
                    LPT.Add(CreateItemA(LPT.AsView.Width, vNombre,vCantidad, encondedString), vValue )
                    FormatButtons(pMenu1A)
                Next
                
                
            End If
        End If
    Catch
        Log("ERROR AL CARGAR LOS ARTÍCULOS")
    End Try
End Sub

Private Sub CreateItemA(Width As Int, Title As String, vCant As String, vFoto As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = LPT.AsView.Height/5   ' Lista de insumos
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 175dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("menuArticulos")
    lblMenu1A.Text = Title
    bntMenu1A.Text = Title
    imgMenu1A.Visible = True
    imgMenu1A.Left = 0
    LBL2A.Text = "CANTIDAD: " & vCant
    Dim bd As BitmapDrawable
    bd.Initialize(Base64ToBitmap(vFoto))
    imgMenu1A.Background = bd
    Return p
End Sub
 

TILogistic

Expert
Licensed User
Longtime User
better performs lazy loading of images.

Search:

Note:
To understand what you want, post an image or example. or a valid sql. To see where you have the problem.

B4X:
    Dim Link As String = "http://www.yateestelamary.com.py/archiventas/datasend.php"
    Dim IdEstado = "ACTVO", IdLocal = 1, IdSeccion = "DEUDA" As String
    Dim Consulta As String = $"SELECT IDARTICULO, NOMBRE, CODIGO, SECCION, RAMO, COSTO, TIPOIVA, STOCKMINIMO, PRECIO1, PRECIO2, STOCK, To_BASE64(FOTO) AS FOTO FROM TBARTICULOS WHERE ESTADO = '${IdEstado}' AND IDLOCAL = '${IdLocal}' AND SECCION <> '${IdSeccion}'"$

    Dim Parameters() As String = Array As String ("act", "CONSULTA", "query", Consulta)
    Wait For (GetData(Link, Parameters)) Complete (DataResult As String)
    Log(DataResult)

1711313106080.png
 
Last edited:
Upvote 0
Top