Using images for multiple resolutions - android

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

Related

High res images on low pixel density screens

Regarding Android's call to provide multiple versions of a bitmap/image, why can't only the highest resolution image be used?
E.g if the xxhdpi image is available - will that be able to scale down to all lower density versions or will it just mean it will scale bigger than the allocated size (View)?
PS: If I'm using a background image, does scaling matter? E.g. should I still provide multiple versions of 1 image to fit different pixel densities?
Usually image scaling operation is resourceful and the outcome might be worse than using pre-scaled image.
It has already been answered several times, but I will answer it again. Btw I'm not myself a big pro in Android, but I will try to answer in the best way possible.
Automatic scaling is a thing in Android, but using that is a waste of resource, we already know that using a PNG Graphic asset is a waste of CPU/GPU power when we can use XML for basic designs (which uses less resources), so why waste more power for downscaling it (which increases app opening time and makes it laggy), simply creating multiple sized images for different display sizes is the best option.
A simple and convenient option is to use a free software like Adobe XD which supports export into different sizes.
Simple answer: Avoid using PNG(or other image format), but when you don't have other options do create multiple sizes to save resources.

Android drawable: different densities or scale

I have designed an in-app keypad for my Android application and I need to provide an image for every key. Currently I've only loaded one large image for each one that is being scaled down to adjust to the layout. Also, this looks nice in every resolution.
Is this approach acceptable or should I provide different images for different screen densities? Currently I've placed those inside the generic drawable directory.
You should. Some mobiles with lower resolution, usually won't have much memory. Loading large images in small screen takes too much memory, which might end up crashing. So if you give different images, then according to density it will take appropriate images. check this out.
It's acceptable in some cases but certainly not optimal.
For best memory performance and the least amount of artifacts I would still recommend to provide alternative bitmap resources for different densities, like the Android documentation recommends.

Working with images in android app development

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.

Which screen size / density combinations should I support for bitmap background image?

I'm writing an application where I will need a number of full screen bitmap backgrounds. Based on my naive reading of Supporting Multiple Screens in the Android documentation, to cover all my bases I should probably have 16 versions of each bitmap: all pairs of [ small, normal, large, xlarge ] and [ ldpi, mdpi, hdpi, xhdpi ]. This should reduce the work the CPU has to do for scaling the images, but will come at great storage cost.
However, this seems wildly inefficient for two reasons:
Not all of these combinations are found in practice.
As I'm just rendering vector art for each physical size (without respect for DPI), pairs like large/mdpi and normal/hdpi (which are both ~ 480x854 pixels) are duplicate files.
So, should I just provide really large images and let the system scale them down? Bite the bullet and provide a lot of duplicate images? Avoid the issue altogether and cobble some code solution with raw resources? Any other ideas? Thanks.
EDIT: Apparently you can create XML bitmap drawables which alias an actual bitmap. That solves the second inefficiency argument. Still, I wonder, what combinations of these do others provide in practice?
You would only provide images at different resolutions if you want that piece of art to be a constant size, regardless of the screen dpi it is displayed on. An icon or a button would be an example of this.
For the background images described here, you don't care what the image dpi is -- you only care what the x * y dimensions are. So you don't have to produce the cross-product of sizes vs. dpi. You only need consider the 4 screen size categories.
And within the 4 screen size categories, you only need store one of the larger sizes (xlarge or large) and let the framework scale that up or down as needed. You can also do the scaling programmatically, to ensure that you don't change the aspect ratio of your background, and you don't crop it.
See also Android game working on all screen sizes which will hopefully attract a better answer.
I would advise providing images for ldpi, mdpi, hdpi and optionally xhdpi (depending on your target users). That will allow you to cover the most commonly used resolutions just fine.
If you end up with the feeling that your application is getting too large (either by deciding to add all possible image sizes or other reasons), you can also look into allowing your application to be moved to an SD card. That way, storage won't be much of an issue anymore. (http://developer.android.com/guide/appendix/install-location.html)

Android: drawable resolutions

I've been through this post (and others) as well as through the documentation about supporting different screen resolutions in Android, but I couldn't find a clear answer to a (simple) question:
Is it ok to just use "res/drawable" for images in an android app?
Background: The only images that are needed in this specific app are the app icon itself and an icon for a notification, there won't be any images in any layout.So in my understanding, if no "hdpi"-, "mdpi"- and "ldpi"-folders are found, Android will use "res/drawable" as the fallback.As the only pitfall with different screen-resolution seems to be that Android will scale images for a specific resolution if no special one is found, this should only be a problem when UPscaling, because the image will get blurry. But if I provide all "hdpi"-images in "res/drawable" (instead of 3 different ones), won't Android just DOWNscale those images if the size is too big?If that's true, I could save some APK-space by just a third of the images.
Follow-Up question: I read that for API-level 3 a dir by the name "drawable-v3" is required. Is that true or is "drawable" the fallback for this API-level also?
Any hint is appreciated.
The images in the drawables folder are assumed to be at mdpi resolution, so they will get scaled up/down if you don't provide the others.
Scaled up images will be low-resolution and look fuzzy. Scaled down images will have pixels missing and look jaggy.
So your app will "work" with only one set of default images, but will look awful on many devices. I strongly advise that you create the images in different sizes, so it looks great on all devices - it's a bit boring, but not hard to do.
It won't be long before we have xhdpi devices, so while you're at it you may want to create those too.
I assume you've read this
Not a complete answer, but: highly downscaled images can and usually do look just as bad as upscaled images (but in a different way), because graphics libraries almost exclusively use interpolation methods for resizing, and interpolation methods are limited in terms of how much they can shrink an image before serious information loss (to about 50% for linear methods and down to about 25% for bicubic methods). This is why most platforms have evolved conventions (like hdpi, mdpi etc.) that let you embed images that are best for each screen size.
I use drawable/ all the time, and then I go to BestBuy and all the local wireless stores and test my apps on small/large/huge(tablet) devices and they look just fine.
Unless you have some reason to target pre-Donut devices (now only 4% of the devices according to http://developer.android.com/resources/dashboard/platform-versions.html), then you should put your bitmaps in one of the -Xdpi directories. The generic "drawable" directory is a synonym of "drawable-mdpi" for compatibility reasons, but a modern well-written app should be putting its drawables in a directory matching the density they are designed for.
res/drawable is the fallback
the caveat is that scaling not only degrades the image but takes processing time too.
I have not even read the API-Level 3 docs yet, sorry for 1/2 an answer
For what it is worth I found the image handling of Android to be tedious and unreliable. The concept of including different size images for different screens will result in large application files bloated with images. There are already screens that don't fit in the standard resolution ranges. I have found it is best not to let android handle the scaling, it seems to create a base image for the smallest screen you target and then scale it up resulting in ordinary looking images on large screens. This happens even if you made the image specifically for the large screen.
My solution that seems to work on everything from a 2" samsung phone to a Sony Tablet is to create images at high resolution and use Bitmap.createScaledBitmap() to get the size I need.
caveat: I am new to Android and have lots to learn.

Categories

Resources