Android Question (Solved) How to Retrieve Blob Image from Sqlite and display in Html

omo

Active Member
Licensed User
Longtime User
I am trying to retrieve database fields from sqlite database such as name, mobile and pic which is to be displayed through webview and html tags as indicated in the code below: I dont have problem with getting ordinary sqlite text fields as well as getting images from android file assest appearing on html code, but i am having problem on how to display blob images from sqlite database into html file below, but work fine if i retrieve image directly from file asset. I like to display blob image from sqlite database on this line here: <img src=" & blobimagefromsqlitedatabase & ".jpg /> below. Please, help!


B4X:
wbview.LoadHtml("<html oncontextmenu='return false;'><body>" & "<img src = 'file:///android_asset/1.jpg' height = 80  width = 100% />"  & "<BR>" & "Name:&nbsp;&nbsp;&nbsp;&nbsp;<font color = 'red'>" & name & "</font><BR><BR>" & "Mobile:&nbsp;&nbsp;&nbsp;&nbsp;<font color = 'red'>" & mobile & "</font><BR>"  &  "<img src=" & blobimagefromsqlitedatabase & ".jpg />" & "<BR>" </body></html>" )
   
WebViewExtras2a.addJavascriptInterface(wbview, "B4A")
WebViewExtras2a.addWebChromeClient(wbview, "")
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
B4X:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAwBAMAAACh2TSJAAAALVBMVEUAAADtNTX////3n5/+9fX719f7zMz5tLTzfHzuQED//f31jY3ybGzxXV3wVFRaxp+rAAAAAXRSTlMAQObYZgAAALVJREFUOMut0rENAjEQRNHdC4kY0QBaAQUQX0QAFSAKIKQEKiAA6VqgIkriApuV1x7pQPz0aWwHljLMpZ0CRDBGoXmeghGYKFJsUo90giAImCgV5OJF+oOgKE48MlGgs2VLBIunWesw0a1ZHqF82c7GmmIfUSpgotOly29DFPFJFDEhkgIT/V5mZuvj6XofKrHU6vyI4u37IYi36aN4h5tL7PJyif1dvCgEpapzISbCTEj5R78BZq5A5Ldh2XYAAAAASUVORK5CYII">

I always convert images to Base64 before inserting (easier to handle). So you can Base64 encode the BLOB (via StringUtils) and use the Base64 string like this (copied it from the www)
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Thank you very much, KMatle, you have opened my eyes to another area of possibilities. I will use your suggested approach and revert back on whatever the outcome.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I always convert images to Base64 before inserting (easier to handle).
:)

But as you know I use my own library to encode/decode Base64 images into and out of databases, as you say it's easier to handle.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I always convert images to Base64 before inserting (easier to handle). So you can Base64 encode the BLOB (via StringUtils) and use the Base64 string like this (copied it from the www)
Thank you so much, KMantle, I followed your suggested approach and I finally got it to work and even opened my eyes to another direction of possibilities. Below is the attached testing code for base64 image encoding and decoding for future interested users.
 

Attachments

  • base64encdec.zip
    12 KB · Views: 497
Last edited:
Upvote 0
Top