Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Saving images into Sqlite database

im wondering if storing images as BLOB in the sqlite database would be a good idea? Does anybody has performance - experience with storing images (blob).

My android app would be a small one, which will need to handle 20 to 100 images (100 kb up to 1MB per image). Worst case: I would say, that my database could reach a size of 100 MB. Does this has significant impact on the database performance? Average case: I guess the average user of my app has 40 images with 200 kb per image, so the size of database would be around 8 MB. Btw. of course the database stores also other "normal" data, so its not a image database only :)

Is storing the path to the image which is stored on the storage(internal or sd card) a better approach? I guess that retrieving the image file path from the database and open and load the image from file would be a little bit slower (but not really significant, since I need to load only two images at once).

A second question: If I would use the second approach (store the path to image file in the database and load the image file): Does a disk cache (DiskLruCache) is something useful in this scenario? Would it bring a significant performance boost? My understanding is that a Disk cache would store bitmaps (instead of encoded jpg or png) and therefore a disc cache would load a bitmap directly from storeage and my app would save the time to decode the image(jpg or png). Is that correct? Btw. In the "database approach" i would store the image already decoded as bitmap. So it seems to me to be something similar as the disc cache, isnt it?

Edit: I forgot to tell you, that i need to store the images persistent on the device. Im not talking about caching images that for example I have retrieved from a web service ...

like image 315
sockeqwe Avatar asked Oct 22 '22 20:10

sockeqwe


1 Answers

My guess will be that the database will get significantly slower if you store that much of information in it, especially when you retrieve the images themselves.

On the other hand, as I get it, every user has the images associated with him downloaded after the application is installed. This is perfect place for using a library another SO user recommended to me in a question of mine I asked couple of days ago: Universal Image Downloader. Here is a link to the thread I speak about.

This library uses on disk caching, but abstracts away all the complexities for you (hopefully, I have not yet tried it, but it seems promising).

like image 149
Boris Strandjev Avatar answered Oct 27 '22 09:10

Boris Strandjev