Hi all clever people,
I hope some-one can assist me with my 'challenges' pertaining to images in SQLite BLOBs
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:
How do I validate the imgBuffer for Null value?
I tried various options for example:
Test for Null
but at runtime I get the error: java.lang.NullPointerException...
So I tried to use a sub to validate:
... 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?
I hope some-one can assist me with my 'challenges' pertaining to images in SQLite BLOBs
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
Else
imgInputStream.InitiaizeFromBytesArray (imgBuffer, 0, imgbuffer.Length)
imgBitmap.Initialize (imgInputStream)
imgInputStream.Close
imgOnScreen.Bitmap = imgBitmap
End If
I tried various options for example:
Test for Null
B4X:
....
If imgBuffer.Length < 1 then<br> ...or... If imgBuffer = Null then
but at runtime I get the error: java.lang.NullPointerException...
So I 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?