Lets consider the following, I have an app with several dozen photos I want to show the user at any given time.
Right now I'm creating multiple files for each image, sizing them for different screen sizes and storing them in their respective drawable folders.
It's increasing the size of my app dramatically.
So here is my question: Is it possible to store the images on a server and use an image library like Picasso, Fresco or something else (open to anything) to fetch that image and scale it down for the device it's running on without risking running out of memory?
I'm worried that fetching a large image, loading it into memory and then resizing it will cause the same problem as trying to display it on older devices with little memory available to them.
You can write methods to request different images sizes from your server based on client info. Just write a method to measure the screen size and then request the appropriate image based on a URL endpoint (like http://myimageserver.com/images/ldpi/image1.png).
You can do optimization post-download, such as scaling, before saving the image to a local file store.
Using a reputable image loading library is a valid method (my own favourite is Glide).
The answer to your question really depends on the number of images you want to show! If there are lots, then yes storing them on a server is probably best, but also the most time-consuming and expensive (both in time and money).
Your other (easier) option is to keep the originals in the assets folder, and use your image loader to scale and load them for you. The correct path for an image in your assets folder is file:///android_asset/your_image_here.jpg. This way, you're only keeping one version of each photo in your apk and they'll load much faster.
Related
I have an app. it has a recyclerView on main screen .
in recyclerView Item layout I have ImageView. the ImageView size is must be responsive. I want to set the images sizes based on screen size. when I received the json images link from server , I do not have any local resources. so I could not put them in mdpi-hdpi-xhdpi-... folders. I want to know what is the standard way for loading images that is received in json format from server . I read a article in this link:
What size to store image on server to use with Android app
my friends says you should fetch all images sizes from servers in json format and make decision what you want to load.
in this link He said send the density to server and it makes decision what is best size for your device.
which one is the most common way ?
If I load all images sizes from server , Should I check density of the device to load which one ?
Not a full answer but in general the device should only have to do one request for getting images, using a library like Glide.
You could use device density to determine the size that you want to ask for, but you and the server should both know beforehand where you can find the url or rather what suffix you have to use to find the lower/higher quality image.
Libraries like Glide handle a lot for you so I would recommend trying all of the features that it provides (like caching) and then afterwards checking if imagesize is really something that you need to optimize.
Especially at the start I wouldn't worry too much about it in small apps because there isn't going to be a noticable difference for users/server load anyways.
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 am creating an app that uses more than two hundred images. To display images, lmageView is used. My question is- Is it necessary to put images in drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi. If I put the images in these four folders, does my app size increases?
Please help me. Thanks in advance.
Well I guess if your image set will not change in the future maybe that's the best place to store them. Your app size will certainly increase, however, if that's a concern you can store them using any cloud service like parse.com or firebase, so you can retrieve them later using a library like picasso
You don't have to put pictures in all folders. There are folders for different image resolutions. You can use a single folder called drawable or just use drawable-mdpi. The app size increase with multiple image versions. There are some disadvantages when you use only one folder.
If you have big resolution images inside your folder: For a presentation, small screen devices have to minimize the image. This costs hardware ressources. If it costs to much ressources, your app will crash.
If you have small resolution images inside your folder: For a presentation, big screen devices have to upscale the image. This will result in bad image quality.
I'm trying to create a CRUD android application.
Now, when the List Activity is shown, it will display the items created along with a thumbnail of the original image.
What is the best practice for displaying a thumbnail in an Android application with Volley? Should I generate a thumbnail for the images uploaded or just re-size the image at the client side?
It's hard to come up with a general answer for this questions because it all depends on how many images you're trying to download and how important showing the thumbnails is.
I would personally generate the thumbnails on the server side as soon as they are uploaded by the user. Doing this has several advantages:
All your app has to do is request the thumbnail and render it, which is much simpler and less CPU-intensive than using Volley's ImageRequest.
Smaller images means less data usage. You definitely don't want your app to download a 10MB 25-megapixel image over a 3G connection just to shrink it to a 100x100 thumbnail that the user might not even care about.
The only drawback that I can think of is that you might have to generate multiple thumbnails, one for each screen size (e.g. one for hdpi screens and another for xxhdpi). This is slightly more expensive on the server side but might make your UI look much better.
Also, remember to cache thumbnails in your app's cache directory so you don't have to re-request them every single time you want to show them.
i'm writing a simple application. i need to handle around 100 images having size dimension 1000*740. images are fixed no need to change. user will see this images like gallery view.
Problem
1.Large number of Images increases .apk filesize .It crosses memory limit(Given by Android market).
2.I placed these images in Drawable folder.Is there any other way to keep this images?
Any Idea?
YOu can host them on a separate site, but you do not have to download them every time. You can download them to an external directory (sd card) and just check if you've got everything you want when starting the app: If you do, you obviously don't have to re-download the shots again.
Is there a reason your images are of that size? If you compress them a bit you should be able to fit a photo in less then half an MB, and I think that the limit is 50mb on the market: You might be able to just squeeze it in.
Upload all the images to a link. Do parsing by using that link.
That's a pretty tough dilemma. Perhaps the user can download the images instead. You could use flickr to host the images.
I would suggest hosting them somewhere and download as "citizen conn" suggested.
Another possibility would be to separate in different sets and have different apk with those (maybe some of them would only have a content provider with some of those pictures). But that's kind of ugly...
Other than that, I don't think there is any way to get around the limit from Android market...