Android Question reading blob from sqlite

merlin2049er

Well-Known Member
Licensed User
Longtime User
B4X:
Dim imgBuffer() As Byte
Dim imgInputStream As InputStream
Dim imgBitmap As Bitmap

dbSQL.Initialize(File.DirDefaultExternal, "tour.db", True)   
dbCursor=dbSQL.ExecQuery2("SELECT ID,Pic FROM Tour WHERE Desc = ?", Array As String(Value))
dbCursor.Position= 0

' get blob pic
imgBuffer = dbCursor.GetBlob ("Pic")
  If imgBuffer = Null Then  ' this is what I need to get solved
    'skip and don't load anything
Else
    imgInputStream.InitializeFromBytesArray(imgBuffer,0,imgBuffer.Length)
    imgBitmap.Initialize2(imgInputStream)
    imgInputStream.Close
   
    ImageView1.Bitmap = imgBitmap
End If

selectionfromspinner1 = dbCursor.GetInt ("ID")
dbCursor.Close

I'm getting an error trying to read the bitmap in my sqlite table...

stuck right on -> imgBitmap.Initialize2(imgInputStream)

any suggestions?
 

LucaMs

Expert
Licensed User
Longtime User
B4X:
Dim imgBuffer() As Byte
Dim imgInputStream As InputStream
Dim imgBitmap As Bitmap

dbSQL.Initialize(File.DirDefaultExternal, "tour.db", True)  
dbCursor=dbSQL.ExecQuery2("SELECT ID,Pic FROM Tour WHERE Desc = ?", Array As String(Value))
dbCursor.Position= 0

' get blob pic
imgBuffer = dbCursor.GetBlob ("Pic")
  If imgBuffer = Null Then  ' this is what I need to get solved
    'skip and don't load anything
Else
    imgInputStream.InitializeFromBytesArray(imgBuffer,0,imgBuffer.Length)
    imgBitmap.Initialize2(imgInputStream)
    imgInputStream.Close
  
    ImageView1.Bitmap = imgBitmap
End If

selectionfromspinner1 = dbCursor.GetInt ("ID")
dbCursor.Close

I'm getting an error trying to read the bitmap in my sqlite table...

stuck right on -> imgBitmap.Initialize2(imgInputStream)

any suggestions?


I'm sorry, I did not read your code, but given the title of the thread, I think you can be useful to the zip file that I have attached here:
http://www.b4x.com/android/forum/threads/sql-and-blobs.34784/
 
Upvote 0

merlin2049er

Well-Known Member
Licensed User
Longtime User
I get error can not load bitmap file and just before that a warning that the bitmap wasn't initialized.
 
Upvote 0
Top