Android Question Showing BLOB image from SQLite field

aklisiewicz

Active Member
Licensed User
Longtime User
I have a table holding JPG images in BLOB. The screens are pretty straightforward. The tables and everything is much more complex, so I just trip it to the rellevant details.

TABLE:_____________
dIMAGES (DiseaseId[Int], ImageName[Str], dImageBin[Blob])



I have a screen based on the list view which lists the image names, then OnClick event I want to open another activity to display selected record with the image from BLOB. Seems pretty simpe but this is first time I do this so I'm not sure how to assign ImageBlob TO ImageView1 in a layout.

I have seen the SQL tutorial, but I'm still not sure how to handle this. Eventually I could even display the images in a Listview, but I'm not sure if CustomListView will handle that, and if it allows to display "full screen" images.

here is a fragment of code I need help with...
Code: Copy
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim SQL1 As SQL
    Dim lblName As Label
    Dim lblSubname As Label
    Dim QueryString2 As String
    Dim Buffer() As Byte
    Dim Cur As Cursor
    Dim ImageInStream As InputStream
    Dim ImageView1 As ImageView
    Dim Bitmap1 As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        SQL1.Initialize(Main.dbFileDir, Main.dbFileName, True)
    End If   
    Activity.Title = "Disease - Images"
    Activity.LoadLayout("DiseaseImageView")
    QueryString2 = "SELECT ID, DiseaseId,  ImageName, dImageBin FROM dIMAGES WHERE ID="&DiseaseImagesList.SelectedImageId
    ShowImage
End Sub

Sub ShowImage
    Buffer = Cur.GetBlob("dImageBin")
   
    '??????????



End Sub

Thanks - Arthur
 
I've seen this before, but it is not very helpful. My problem is a little different as I have the code working fine now.
The problem is that some of the BLOB images can be opened and some cannot. The images are not saved with B4A but some other App. The question is if there are any different methods of saving image to BLOB (for example using PHP App) which can cause incompatybility ?
is it possible that images are compressed, encrypted etc. while saved in BLOB ? There must be some kind of pattern which makes some readable and some not. I noticed when I manually add BLOB image with SQLite EXPERT program everything woks fine, and I can see an image, but when I add an image with PHP App it is not accessible.

Arthur
 
Upvote 0
The blobs are not compressed by SQLite. A blob is just a set of bytes. If the image was converted correctly to a set of bytes then you should be able to extract it. You can try to extract one of the problematic images and save it to a file on the external storage. Now copy it to your PC and check the file there. Compare it to the original image file.
 
Upvote 0
Back
Top