Android Question Save image links in the database and open them in a listview

Discussion in 'Android Questions' started by Lowegaterecords, Sep 18, 2018.

  1. Lowegaterecords

    Lowegaterecords Member Licensed User

    Precedentemente ho postato una domanda sull'inserimento di immagini di BLOB in un database e sul caricamento in un listview.
    QUI: Salvare un'immagine dalla galleria di smartphone nel database e caricarla in un listview.

    Ora come i BLOB sqllite accettano solo uno dei due formati di immagine e Android limita il caricamento di super immagini a 2mb ecc. Come descritto in una domanda. Voglio provare a salvare l'immagine selezionata dalla galleria di smatphone e salvarla in DirAsset e salvare il collegamento nel database per visualizzare le immagini in un listview, ma non riesco a trovare la strada! Ho provato alcune soluzioni ma non sono buone. Come fare un esempio?
    Last edited: Sep 18, 2018
  2. ronell

    ronell Well-Known Member Licensed User

    it is not possible to write anything in dirassets, use RuntimePermissions.GetSafeDirDefaultExternal("") instead .. see this

    you don't need to save the link or full path of the image you want to save in your db, just the image name will do .. use ContentChooser to save the images from gallery search the forum for examples

    to display the image , get the GetSafeDirDefaultExternal path + the image name

    dim dir as string = RuntimePermissions.GetSafeDirDefaultExternal("")

    Dim bmp As Bitmap = LoadBitmap(dir,"image.png")

    imgview.Bitmap = bmp
  3. Mahares

    Mahares Well Known Member Licensed User

    Hi @ronell
    You really do not need to copy the images to any other folder. They can stay in the assets folder and do this to extract the image:
    Dim bmp As Bitmap = LoadBitmap(File.DirAssets,"image.png")
    or you can load them to the listview, unless of course he plans to modify the images.
  4. Lowegaterecords

    Lowegaterecords Member Licensed User

    The real problem is this: I save the images jpg and jpeg in the db converting them in bytes. but I get an error loading the jpeg blobs saved in the db. Not finding the solution I thought that saving the image in the DirInternal and saving the link in the db I would have solved the problem of loading.
  5. ronell

    ronell Well-Known Member Licensed User

    the images he wants to display will not come from the assets folder.

    see #2 post .. use contentchooser to open gallery and wait for the result sub, get the image file then save it on other directory and also save the image name in your local db
  6. Lowegaterecords

    Lowegaterecords Member Licensed User

    Hello ronelle, thanks for the advice is what I try to do but I can not you could show me an example?
  7. Lowegaterecords

    Lowegaterecords Member Licensed User

    count to receive this error at the row load : java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
  8. npsonic

    npsonic Active Member Licensed User

    If I understand correctly, this is what you want?

    images: KeyValueStore2, clv: CustomListView and picasso: Picasso

    Sub Chooser_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
    'Without copy
    'With copy
    Log("No image selected")
    End If
    End Sub

    Sub FillCLV
    Dim keys As List = images.ListKeys
    Dim xui As XUI
    For Each key In keys
    Dim p As B4XView = xui.CreatePanel("")
    000, clv.AsView.Width, 100dip)
            p.Color = 
    End Sub

    Sub CLV_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 20
    For i = 0 To clv.Size - 1 Step 1
    Dim p As B4XView = clv.GetPanel(i)
    If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
                If p.NumberOfViews = 0 Then
    Dim iv As ImageView : iv.Initialize("")
                    p.AddView(iv,(p.Width - p.Height) / 
    End If
    'not visible
                If p.NumberOfViews > 0 Then
    '<--- remove the layout
                End If
    End If
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice