Display an image from a BLOB
Does someone successfully displayed an image from a BLOB. The blob comes out of a SQLLITE DataBase.
Using the image property of the image view just gives me this error :
[WARN] invalid image type. expected either TiBlob or TiFile, was: NSCFString in -[TiUIImageView setImage_:] (TiUIImageView.m:493)
For what I can see in the Titanium debuger my BLOB is a well formed BLOB.
As my BLOB retreived from the db appears to be typed as an OBject is there a way to transtype the data from the db to make sure it's a blob.
//e.row.pict is the BLOB of the selected row in the database
var blob=e.row.pict;
logoimage = Titanium.UI.createImageView({
image:blob,
height:60,
width:80,
left:10,
top:10
});
4 Answers
-
Hello, I have exactly the same issue, here is my code:
var authorAvatar = Ti.UI.createImageView({}); win.add(authorAvatar); var base64img = 'bla-bla-bla'; //put here any base64 image string for test var imageBlob = Ti.Utils.base64decode(base64img); authorAvatar.image = imageBlob;
it shows up nothing. if I call
authorAvatar.image = '/images/test.png'
it appears fine.I also tried to save Blob as temp file like that:
var authorAvatar = Ti.UI.createImageView({}); win.add(authorAvatar); var base64img = 'bla-bla-bla'; //put here any base64 image string for test var imageBlob = Ti.Utils.base64decode(base64img ); var file = Titanium.Filesystem.createTempFile(Titanium.Filesystem.resourcesDirectory); file.write(imageBlob); authorAvatar.image = file.nativePath;
No results, no warning and errors on debugging console, no picture. Reproduced on Android platform. Any ideas?
Thx a lot for your help -
Is this question still not answered?
You might try to save that BLOB to a temporary file and use that file in your image view. :)
Here's how I did it with the toImage()-function.
var theMap = win1.toImage(); var file = Titanium.Filesystem.createTempFile(Titanium.Filesystem.resourcesDirectory); Ti.API.info('size = ' + file.size); file.write(theMap);
Then you can use
file.nativePath
:-) -
I was thinking to that too this week. I wasn't sure if this was a correct practice performance wise ? Anyone tried it enough to tell it is a bad idea ? In fact, I think it is a bad practice…but didn't tried it yet !
-
I am trying to do this as well but unclear on how to save the BLOB to a temporary file. Given the example where blob = e.row.pict would you just put that in the file.write->file.write(e.row.pict)? Or do you need to create a window, or view and add the e.row.pict to that somehow (how?) so you can call the toImage() method before writing it to the temporary file?