LoadBitmapSample used with Sqlite blob?

MDEnt

Member
Licensed User
Longtime User
Hello all - I haven't yet used LoadBitmapSample and was wondering the syntax (or if it is possible) to retrieve images directly from a SQlite database and then just sample them for the view. I currently have many images loading successfully in a ListView (in a loop), but since they are only thumbnail size in the view compared to their actual size, it would be great to free up resources. Below is a snippet where my image is retrieved from SQlite.

B4X:
                        Dim Buffer() As Byte
             Buffer = cur1.GetBlob("image")
             Dim InputStream As InputStream
             InputStream.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
             Dim Bitmap1 As Bitmap
             Bitmap1.Initialize2(InputStream)
             InputStream.Close
             ListView1.AddTwoLinesAndBitmap.... ,Bitmap1)
 

BvdB

Member
Licensed User
Longtime User
Hello all - I haven't yet used LoadBitmapSample and was wondering the syntax (or if it is possible) to retrieve images directly from a SQlite database and then just sample them for the view. I currently have many images loading successfully in a ListView (in a loop), but since they are only thumbnail size in the view compared to their actual size, it would be great to free up resources. Below is a snippet where my image is retrieved from SQlite.

B4X:
             Dim Buffer() As Byte
             Buffer = cur1.GetBlob("image")
             Dim InputStream As InputStream
             InputStream.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
             Dim Bitmap1 As Bitmap
             Bitmap1.Initialize2(InputStream)
             InputStream.Close
             ListView1.AddTwoLinesAndBitmap.... ,Bitmap1)

Hi all clever people,

I hope some-one can assist me with my 'challenges' pertaining to images in SQLite BLOBs

I ran into a similar 'constraint' about BLOBs, and I have a question, but let me first briefly explain what I try to achieve...
I want to load an image from a BLOB field in a SQLite database table and display it as an image on screen.

All the samples and discussions that I read, load the bitmaps from storage and not from a database, which is not what I want to do here.
I managed to get it working but I have records in the table that may not contain an image. Therefore I need to validate if the BLOB field is Null, or I need to ensure I store a very small dummy image if an valid image is not saved and/or carry another Boolean field which indicates whether a image is present or not.
I don't want to do this unless there is no other way of validating for an empty (Null) BLOB field in the Database.

The following code works 100% if an image is present in the BLOB field:

B4X:
Dim readCursor as Cursor
Dim imgBuffer as Byte
Dim imgInputStream as InputStream
Dim imgBitmap as Bitmap
Dim imgOnScreen as ImageView

... the SQL statements to populate the readCursor....

imgBuffer = readCursor.GetBlob ("ImageCol")

'before I proceed from here I want to validate if the  imageBuffer is Null, because it can be empty (containing no image).
If imgBuffer = Null then  ' this is what I need to get solved
    'skip and don't load anything
Else
     imgInputStream.InitiaizeFromBytesArray (imgBuffer, 0, imgbuffer.Length)
     imgBitmap.Initialize (imgInputStream)
     imgInputStream.Close
     imgOnScreen.Bitmap = imgBitmap
End If
...

How do I validate the imgBuffer for Null value?
I tried various options for example:
Test for Null

B4X:
....
If imgBuffer.Length < 1 then
...or...
If imgBuffer = Null then
....
but at runtime I get the error: java.lang.NullPointerException...

So tried to use a sub to validate:
B4X:
... 
If isNullBuffer (imgBuffer) = False then
...
...
End If

Sub isNullBuffer (bufferValue as Object) as Boolean

Try
     If bufferValue <> Null then
            Return False
     End If
Catch
Return True
End Try

End Sub

... but during execution, after executing the If statement, the caret jumps straight to the End Try statement.
reached the End Sub, return a True value by default and then throw an exception on imgInputStream.InitiaizeFromBytesArray.....

How do I validate for a Null value in a BLOB or Byte?
 
Upvote 0

BvdB

Member
Licensed User
Longtime User
Hello all - I haven't yet used LoadBitmapSample and was wondering the syntax (or if it is possible) to retrieve images directly from a SQlite database and then just sample them for the view. I currently have many images loading successfully in a ListView (in a loop), but since they are only thumbnail size in the view compared to their actual size, it would be great to free up resources. Below is a snippet where my image is retrieved from SQlite.

B4X:
                        Dim Buffer() As Byte
             Buffer = cur1.GetBlob("image")
             Dim InputStream As InputStream
             InputStream.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
             Dim Bitmap1 As Bitmap
             Bitmap1.Initialize2(InputStream)
             InputStream.Close
             ListView1.AddTwoLinesAndBitmap.... ,Bitmap1)
Please start a new thread for this question.
Did that
 
Upvote 0
Top