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.
Related
I have a room data base with 2 entities that save images as bitmaps. But I've encountered a problem where if I try to save images that are larges(1.5MB+) which are most of the pictures taken by modern smartphones, when I try to retrieve it, the app crushes because it can only have 1MB of data.
I've tried to compress the bitmap before inserting it using https://github.com/zetbaitsu/Compressor, but it's complicated because you can't limit the size, and bitmaps are larger than what they are on files.
So I thought about 3 approaches for saving the images, an my question is which one is the best(and easy to implement), or whether there is a better approach than those.
compressing the bitmaps before saving - which is complicated and didn't work for very large files.
saving the Uri in the database instead, but if you delete the image from the phone than the image isn't saved in the database which is unexpected behavior for the user.
saving the image in storage than saving the Uri to the image - but it requires asking for permission to WRITE_EXTERNAL_STORAGE.
Thanks a lot in advance!
I am converting image as a byte array to store in the database in android. For this, I have to convert image both at the time of storing and reading. I can definitely store all image in variables during runtime at once but it might take a lot of space if there are a lot of images in the database. Does conversion actually take a lot of resources ? in that case I will use other methods to store like in file (I haven't used file before so will have to learn it first, trying to save effort :) ).
I think it depends on how many images are you planning to save in the database. For instance: if it is the user profile image, which is gonna be one image per user, I think it is okay. But, if it is something like images that the user can upload as many images as he likes, I don't really think it is a good idea. There are advantages and disadvantages on both.
There are plenty discussions about those two approaches:
Storing images in a database versus a filesystem
Why is it considered bad to store images in a database?
Storing Images in DB - Yea or Nay?
What is the best place for storing uploaded images, SQL database or disk file system?
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.
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).