Android Question Bitmap will not load (extracting from DB)

chinku_chan

New Member
Hi Good People,
I REALLY REALLY need help on this one. I've been stuck on this error for two days now and I just don't get it.

I have attached an image of where the error occurs. Basically I'm Creating a scrollview and other controls "dynamically" to which I then load various values (pulled from a SQLITE DB). Everything works fine except for when I attempt to initialize the Bitmap that will hold the Picture/Blob loaded from the DB.

FUNNY thing is, this "LastException java.lang.RuntimeException: Error Loading bitmap" error ONLY does not here. I placed a 'test' imageView on a random activity and have managed to load images from the DB successfully. I don't get why it wont work here.

PLEASE HELP. THANKS!!!
 

Attachments

  • 2.PNG
    17.1 KB · Views: 241

Mahares

Expert
Licensed User
Longtime User
I think your code is correct, but you need to position the cursor to the first record. See where I added the line for you.
B4X:
Main.cur.Position=0  'Add this line
Dim Buffer() as Byte
Buffer=Main.cur.GetBlob(“Picture”)
 
Upvote 0

chinku_chan

New Member
THANKS for your response

The cursor is already initialized to 0 initially (runs in a loop) so that works OK - as other tables values are successfully pulled from the DB.
So that is not the issue. It's just the IMAGE extraction that's the issue. PLEASE could you maybe take a look at my code and the comments I've put in.


B4X:
Dim ListOfMaps As List
            ListOfMaps.Initialize
            Dim aMap As Map
                aMap.Initialize
                aMap.Put("ProductID", NewProdID)
                aMap.Put("Name", txtProdName.Text)
                aMap.Put("Size", txtSize.Text)
                aMap.Put("Price", txtPrice.Text)
                aMap.Put("Description", txtProdDes.Text)
                aMap.Put("Type", spType.SelectedItem)
                aMap.Put("ArtistID_fk", Main.globID)

                'THIS IS WHERE I INSERT THE IMAGE WHICH I LATER TRY TO EXTRACT. AM I DOING IT RIGHT?
                If picSelected Then
                    aMap.Put("Picture", imgSelected.Bitmap) 'THIS IS WHERE I INSERT THE IMAGE FROM GALLERY
                Else
                  imgSelected.Bitmap = LoadBitmap(File.DirAssets, "empty_gallery.png")
                  aMap.Put("Picture", imgSelected.Bitmap)
                End If
               
                ListOfMaps.Add(aMap)
       
            DBUtils.InsertMaps(Main.aSQL,Main.DBTableProduct, ListOfMaps)

'=================================================================================
'I USE THIS METHOD TO EXTRACT THE IMAGE AND THE ERROR OCCURS HERE
B4X:
 Sub getImage
    Dim Buffer() As Byte
    Dim inpStream As InputStream
    Dim Bitmap1 As Bitmap
       
    Buffer = Null
   
    If Main.cur.Getstring("Picture") <> Null Then
        Buffer =  Main.cur.GetBlob("Picture")
    End If

    If Buffer = Null Then
       
    Else
        inpStream.InitializeFromBytesArray(Buffer, 0, Buffer.Length    )
        Bitmap1.Initialize2(inpStream) 'ERROR OCCURS HERE
    End If 
    inpStream.Close

End Sub

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