The app I am making takes videos and pictures and displays them in a gridview. My hope is that the user will use my app frequently and take a very large quantity of videos and pictures. The problem I'm trying to figure out what route to take when storing the bitmap thumbnails. I'm currently using a SQlite database to store all the bytes and then querying them and creating a bitmap to be displayed. Even if I'm doing this in a background thread, this seems really inefficient especially as the database grows and there is more data to query through.
I feel using a memory cache would allow for faster retrieval and a better user interface. However, I'm afraid that if the user creates a lot of thumbnails then I run the risk of running out of memory.
My main questions are:
Is storing a bunch of thumbnails even something to be concerned about when caching?
Are there any advantages of using a SQlite database in this situation?
Thanks
You shouldn't store the images as bytes, you should store the images as files in the cache folder and in you db you should only store the paths towards the images (or the name of the images if you know the folder). You should cache the thumbnails also, it will increase the speed when he looks through the list of thumbnails (resizing an image takes some time).
P.S. You can use some 3rd part libraries for this.
Related
I want to make an Android application that has the same look as Instagram, which means every profile has a gallery of photos.
My question is about storing and retrieve those photos. I want to know what is the best practice for photo storage in a database (MySQL), more precisely:
Should I store photos with original size (2mb for example) or resize them with smaller size?
Should I store them with two version (smaller size photo, and normal size photo)?
Saving images in the database looks like overkill, it's not needed. Saving on disk should be fine.
Although you should focus on your business logic & leave this to image libraries which does this stuff & do best for memory & performance.
Some famous libs are:
Picasso
Glide
Universal image loader
Fresco
& you will find many more
Almost each library does lots of stuff for you, such as:
In memory cache(LRU Cache) - so that UI thread is not blocked from doing I/O
operation from disks
Disk Cache - To keep images saved for further
app sessions, also when memory cache reaches its limit its have to be
evicted from it., you can specify disk cache size.
Various image scaling strategies
Image transformations
Clearing up bitmaps for freeing up memory
Network operations on background threads
Background threads management & so on..
My suggestion is to go with one of the image library
I dont think the best practice is to store the photos in a database.
In the DB you store the link/location of the photos example a url to a photo.
About smaller size photo it depends on what you are trying to accomplish because now you need more space to pay for and maybe less bandwidth because you can put thumbnails and let it only load the original size when a user clicks on it. So it all depends what and how you want to archieve
Best practice for storing images is to simply cache them as files and not save them in a database. You could save them as blobs in an sql db but they should be less than 32px by 32px to make things smooth. Everything else should be saved as files. Let me give you an example of WhatsApp.
WhatApp caches most of it's images as files and only saves the pixelated thumbnail in a database.
I want to make image backup through my Application what is the best way for storing large amount of data . I tried to save image in sqlite database it worked fine for small amount of data in case of large amount it shows MemoryOutOfBoundExceptions after increasing the Heep size(android:largeHeap="true").
please help me guys .
If you want to save only image or any file try to save only path of that file in database.After that you can get file path by normal SQL query and access file from file path.
Instead of Storing Large data in Application you have to store it DataBase so it will speed up your Application and you have no Exception produce like OutOfMemoryException in your Application.
You don't store images in databases, that makes the database huge and slows it down. Store the images to disk and store the path to the file in the database. This will make the database a lot lighter and faster.
If you're developing for Android, i'd also recommend using something like Picasso, Fresco or Glide to display your images too. They cache the image and use memory efficiently when doing operations like scaling images.
I wonder which way is better to store images in memory:
Storing images as BLOB in DB
or
Saving images to file and store only path to it in database
What way is more efficient? I suppose that storing files' paths requires more operations because we need to refer to DB and then to file, but I'm not sure if this is less efficent than keeping whole images in DB.
In a nutshell:
If size of your images are fairly small and number of images are also less, go for storing directly in database, as it is simpler to manage.
However, if size of your images in large and also number of images is high, go for saving in file system. Typically, database don't show any performance issues until 10MB for an average mobile.
Let me know if you find any other criteria of judgement.
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 ...
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).
I am making a game in which I want user to give some featured items at run time from server. Currently I am saving images as Blob in sqlite db and that is really putting bad impact in overall performance.
If I write images on SD card then there are following possible two scenarios.
1) All mobiles do not have SD card
2) Any one can see/reuse/delete images
I don't want these things to happen. Is there any way that I can save images in drawable folder where no one except me can see images?