I am about to publish an android application which uses several images with different resolutions. I have found the hard way (with a crash) that putting all images in drawable folder causes a OutOfMemory Exception because images are scaled up. By putting all images in a high dpi folder like drawable-xxhdpi the problem goes away.
My question is : should I arrange images according to their resolution to the respective folders ? Will that make any difference ? Will android scale-down an image found in drawable-xxhdpi even if it is a low resolution one ?
You may want to use Glide for rendering drawable in your app. Glide provides you mean to auto scale the images according to your image holder size. This also caches the images for faster access (if you were to use network images). Read the doc and see if it helps you.
Related
Is it Ok to provide image resources for all densities in Android (LDPI, MDPI, HDPI...) and that the system can choose the appropriate one for each device, or it is more efficient to provide only high resolution ones and downscale them to devices with lower resolution? In the last case, can the system itself do the downsampling, or will it cause a lot of OutOfMemory errors and slow performance. On the other hand, you can do downsample the images using the right classes that provide the Android SDK, but will you have to downsample each time you load the app? Any help will be appreciated.
Instead of using a raw image format, you can use a Vector Graphics instead
Your default android application's icon is actually a vector resource
More guidelines about this can be found here:
Add Multi-Density Vector Graphics
Yes, providing different scales would be the more appropriate way. Yes again as downscaling an image isn't efficient as it slows down the app and also gives memory exception. But that's setting the resource directly using ImageView. As other open sources like Picasso can be used to fit the resource in the view (still slow). Now, having separate scales for a particular image is best. As you don't have to programmatically get the user's device's resolution and adjust scaling because the app will automatically choose the best scale from the folders (faster way). You don't even have to worry about memory exception. It's like no work. You just have to keep necessary scales of the resource in your drawable and you're good to go. You can always find online converters, they rescale your resource to all scales and upload it in a . zip file. Good luck!
You can also use single Vector image for resources to reduce your apk size
On my android project I have 5 kind ok drawable: xxhpdi, xhpid, hpdi, mpdi et lpdi
But I don't realy understand in witch file set my images
I had a look to this link: http://developer.android.com/guide/practices/screens_support.html
I need to class my pictures by size and by px/in
I have ic_launcher in my folders:
xxhpdi => 144*144px
xhpdi => 96*96px
hpdi => 72*72px
mpdi => 48*48px
lpdi => vide
But they are all in 72*72 px/in
I'd like to know how to set my pictures in res folders, why not just have a xxhpdi image ?
and did we always need to have 5 image, it weighed the application.
Thanks
Resolutions were explained in other answers. Regarding the question about weight of the app, You could provide different apks for different devices via Android Market, so particular apk would include only images for particular screen.
Moreover, the same time You don't need to do simultaneous development of many branches etc. just because of images differences, just follow Android documentation on support multiple screens and produce separate builds using aapt -c key which would allow You to have only necessary configuration included in every build..
The Android system will choose the closest 'density bucket' (drawable folder) to the current device, and use that for some final resizing to the devices exact size.
Its a guideline to provide an image for every density bucket to ensure the best result, but in practice often an image will look just fine by only adding it in 1 or 2 folders.
If you have a problem with having some big images that make your app huge, cause you have to add them 5 times, you could try around with adding those only in 1 or 2 folders.
Per example, xxhdpi is only nexus 10 at the moment, are you even really supporting that? ldpi is also not very common anymore. You could try adding it only in xhdpi, and scaling will probably look fine.
For the rest your images shouldn't be much more than some simple icons, which shouldn't take up a lot of space.
tl;dr: Yes if you want to follow guidelines for best result, but you can probably cut on app size without people actually noticing.
Android comes different screen resolutions, each resolution depends on screen width/height.For mobiles you place the corresponding sized images in res folder. During run time device itself find the resolution and re size the resolution it needs. For some cases you may get issues like image squeeze etc. At these time you place the corresponding image sizes with their corresponding res folder with same names.
I wrote a little toole for this.(BitmapCat) It scaled png-, bmp-, and jpg images for Android apps in:
ldpi(low-density)
mdpi(medium-density)
hdpi(high-density)
xhdpi(extra-high-density)
xxhdpi(extra-extra-high-density)
Here you can download it: http://blog.axxg.de/bitmapcat-en/
Very much a newbie question here but I cannot find a clear answer on the net or in the books I have. I am designing an app to be compatible with all sizes of android devices and I want to display a images in my app. I understand that android automatically scales images to suit the resolution of the screen being displayed.
My question is what do I look for in the images I use? E.g. I have a picture that's 2418 x 2192 # 240dpi. As far as I can tell, this should be perfect for a larger screen such as a tablet. If I put this into the xhdpi image folder in my project will it be detected by other devices and scaled to suit their dimensions/resolutions? Do I have to create 3 different versions of this image in photoshop and put it into the relevant dpi folders?
I can't find a nice beginners tutorial for this stuff so haven't a clue what I'm doing!
This is the best place to start for multiple screen size support:
http://developer.android.com/guide/practices/screens_support.html
The short answer is, yes, you place the images in the different directories based on resolution and Android will select which image to use based on the device's properties. You should make a smaller set of images, for example, for mdpi and hdpi. You don't "have to" do that, and if you just place the image into drawable it can be scaled down, but that's generally not the best way to go.
This is something you'll deal with on just about all project, because there simply are so many Android devices. This resource has helped me greatly.
If you have a resource in only ONE folder, Android will scale it for you. The different drawable folders are intended to allow the developer to provide properly scaled images with minimal effort. For example, you'll want to provide an xhdpi in addition to the "standard" mdpi image to make assets look better on high-resolution devices. The app would work fine (and have scaled images) in all resolutions, even if you provided only a single image. However, if you provided a xhdpi drawable, then there's a bit of overhead to scale all of those down, and especially for icons, the results may not look very good (or even be recognizable).
I generally provide assets for mdpi and xhdpi, but if the app will see frequent use on low-res devices, I provide the ldpi as well. If possible, I include all four.
Note: The image you mention is much too large to be included in the UI resources and would probably best be placed in assets and loaded on request. Even on xhdpi devices, it would have to be scaled down.
I'm quite new to Android development. My understanding is that you can create several versions of the same image with different sizes and put them into the folders drawable-ldpi, drawable-mdpi, drawable-hdpi.
It seems obvious to me that you can handle this problem "the lazy way" by just resizing one image depending on the device's pixel density. For this I programmatically find out what density the device has, like ldpi. The implementation itself is not the problem. I'm just afraid of any drawbacks (that prevent me later from running the app on different devices).
So, are there any (major) drawbacks of scaling images automatically ?
In which of the three folders do I put the image so that the compiler can find it?
You would put the image in your regular drawable folder. That way any phone can find it.
While you can programatically shrink images, shrinking usually has the effect of reducing image detail and causing jaggies.
Adding in smaller assets will also reduce memory usage on smaller phones. Keep in mind that some Android phones are notoriously bad with memory (see: HTC Status), so any and all savings help.
I would recommend just photoshop scaling images down large images yourself. For smaller images, it is not as big a deal.
Android does auto-scale and it works fine in some cases, but it doesn't work for many, notably small images with important details like text. Scaling a larger image down blurs those details. Scaling a smaller image up is worse. This is why icons files have been multi-resolution since the very early days of GUIs. To wit, text scaling is hugely complicated. Ask any font designer, and note Adobe built a company on algorithms to do it automatically.
it's on mdpi folder. It'll change the size automatically. But is not recommended since the image quality drops.
I was wondering if there is a way for using one set of images for all the resolutions. I have an application, and I want to port it on all the android resolutions but I don't want to store 3 sets of images, for every resolution category. What would be the best practice to use as less images as possible.
Thank you!
Sure, you can provide only one set of images, in the base drawable directory, and Android will automatically resize as required.
This may result in aliasing and images that are not as clear as would be possible if you were to provide images sized properly.
You probably mean density, not resolution (in Android, applications do not work directly with resolution).
Actually, you don't need to support all 3 densities. Quote from developer.android.com:
This pre-scaling mechanism works independently of the source. For instance, an application targeted for a high-density screen may have bitmaps only in the res/drawable-hdpi/ directory. If one of the bitmaps is a 240x240 icon and is loaded on a medium-density screen, the resulting bitmap will measure 160x160.
I've done simple test: removed ldpi and mdpi density images, launched my app on mdpi skin and it scaled hdpi images nicely. It's not the best practice, but android's prescaling does its part as described.
Please read this for more details.
I wrote a tool which makes this all a lot easier to manage. Although the images are stored in separate directories - the tool shows all resolutions together, and lets you auto-scale from one to another.
you can get it here: http://hobbyistsoftware.com/AndroidImageViewer