Android where to save images (private) ?? how to dynamically update images collection? - android

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?

Related

Best practices for photo storage

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.

Android: Working with images and SQLite [duplicate]

This question already has answers here:
What is the best way to store the image in the memory of app?
(4 answers)
Closed 6 years ago.
I'd like to be able to programmatically work with Images, ImageViews, Drawables, and SQLite blobs (byte arrays). I inevitably want to be able to have a program that lets me acquire images from the Gallery app or something similar (ie camera), and then place them in a gallery construct within my app and work with them from there. Storing them in SQLite database's as needed.
I haven't come across anything that works. Much of it is deprecated. I have a simple project that is working with text in a SQLite database, and am now trying images.
If you can show or send me someplace that shows how to work with these constructs that would be great. Though to be more specific for this thread I'll state a few things I'd like to do:
Converting Drawables to ImageViews and converting Drawables to SQLite blobs.
Acquiring images from outside the program and placing them in the Drawables section.
Best constructs for working with images.
Thanks,
convert a image to byte[] and easy to store SQlite db
Don't store images in SQLite, instead of saving images save their path into SQLite, and later you can load image from their path.
and if you are loading images from web then you can use Universal Image Loader. It will display and store images in device memory and you can load images offline anytime with same url.
Instead of saving image as blob, save the image url. Or save it in external file in sd card or phone memory.
To save it in a link,
When the user selects an image from gallery. Call the upload image function ( it can be a BoundService ). You can find it by googling it.
When the upload image is successfull, ull get the image url in Json.
Just save that image link in your sqlite database.
Hope it helps.

how can I programmatically remove the image from a folder “Drawable”?

I am developing an E-commerce application. Here I need to show lots of product images when the app is up. I have stored few product images in the drawable folder to reduce the network usage. I am planning to download delta product images when the new product is added in my back end product inventory and save it in SQLite database.
In the app I have to refer two different path ( drawable and SQLite database) to get all product images.
So how can I move the initial fish images in drawable folder to SQLite database at the time of APK generation OR after the app installation (in onCreate method of my MainActivity). And I also need to delete those initial images in the drawable folder after moving it to SQLite database.
Any suggestions are appreciated. Thank you in advance.
The bottom line is that if you deliver with content bound into your APK, it will remain there. Assuming you're planning on distributing through the Google Play store, the only way to modify this via an app update, which is obviously extremely hacky. So if your goal is to discard initial drawable resources, you cannot do this.
My advice is to compress the images as much as possible and only provide one image size which you can resize at runtime, so use the nodpi drawable resource folder (i.e. drawable-nodpi)
The alternative is to download the images via network. Though you say you don't want to do that the file sizes can be made quite small and so the download fast in most cases, so unless you're sure network connectivity will be a problem for your users it's a viable option.

Sqlite database and memory cache for thumbnail storage

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.

what is the best practice store images in android in SD card or in SQL lite DB?

I want to store sample images. what is the best efficient way weather to store on SD card or in DB?
if the images are not big(2-3 KB) and the collection of them is not supposed to be expanded then you can save them to db. But it would be harder to write them, read them. On the other hand the user won't be able to do anything with them.
Otherwise, if you want to let user to expand the image collection or the images are rather big you should store them to sd card.
Anyway, you should be aware of space lackness and treat those cases appropriately.

Categories

Resources