I am working on an Android application where I am getting my data which includes images stored as blobs from a database, and then once I get this data in my application, I am transforming all of these into bitmaps, and storing the data in ArrayList for later use. When doing this for two dozen images it takes around 8 seconds; how can I create the bitmaps quicker. The images vary in height. In a for loop I am turning the image string into a byte array and then using BitmapFactory.decodeByteArray. I am also using options.inSampleSize = 4.
Read images from database and store into local cache memory and then you read images from cache memory,it's efficient way of displaying bitmap.
Refer this link:
https://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
Related
I am working with the cards (cardView) and trying to store the images inside the array (array to string; store that in cache and when required unpack back to array). My question is: what is the most convenient way to store the images in an array?
Store the bitmaps (bitmapToString etc)? Turn the bitmaps (I get the images from the gallery and camera) into URIs? Absolute paths?
The number of images is small (3-4), so, I guess, there's no need in a DB.
Android Bitmap objects are not good candidates for storing in Java arrays - they are very large objects so you run the risk of an OutOfMemoryException. It is easy to create a memory leak if you are not careful.
If you have to get some photos from the gallery as Bitmap and retain them in your app, one of the patterns that is normally used is writing the Bitmap to the app's internal storage (covered here.
If you need a reference to the stored photo, you can save the filename or a Uri that represents the photo or image.
Then the problem of loading Bitmaps etc. into an ImageView is solved with libraries like Picasso or Glide. You can use these to load from the local file system, or from online.
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.
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 am developing an application that requires me to retrieve multiple images from a Cache database and then display them on an Application.
At the moment i write the images to binary array's and then convert them to bitmap images on the application, but the Base64 string is about 30% larger that the actual image.
What encoding method should i use to reduce the overhead involved in storing these images?
You can store the images in the SDCard, in the device cache, or in a database. Not sure which you mean but here are some guides.
This post explains how to store an image in any location on the sdcard:
Save bitmap to location
This one explains how to store in the device cache partition: Android, Saving and loading a bitmap in cache from different activities
And this guide explains saving and retrieving bitmaps to/from a database: http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html
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).