How to select source density of image when using android ui utils - android

I am generating nine patch images using android ui utils
I am not sure of what to select for the source density field.
How do i know the right density to choose?
Is there a way to determine this from my image dimensions?
Thanks

It's source density, like if designer draw for mdpi (for example, screen resolution is 320x480), and give you images in this density, you need choose mdpi.
Also i recommend you this nine patch editor.

Related

Can we use images in one image density without any quality lost? (Android Image Density)

I work on an image sequence animation. I have 75 png files. I want to use images in one size without adding mdpi, hdpi, xhdpi etc types and get the same view on all devices. Is there a way to do this?
Best,
You Can try the following way may help you
(1)use only mipmap-xhdpi folder and create image according to mipmap-xhdpi density requireda and put all in xhdpi.
(2)Use Vector Drawable/Vector Graphic features in Android studio....Please read detail from https://developer.android.com/training/multiscreen/screendensities
(3)Please try to create the nine-patch image...Please read from https://developer.android.com/guide/topics/graphics/drawables#nine-patch.
https://developer.android.com/studio/write/draw9patch

Android Studio image resolution

I have an image with resolution 300x450. I want to use it on an Android Studio app.
When I create a new "Image Asset", the pic looses its resolution, and if I select manually the resolution at the ImageView, it pixels.
What can I try?
Thank you
Fixed. The problem is, that you mustn´t to insert it as "Image Asset", you just have to drag the pic, to the Drawable/xhdpi folder. Then, you can to use it, with no problems.
The image size you are using should have the resolution for the highest density (xxxhdpi) beacause when you create a new Image Asset, Android Studio create N different drawables for that image, one for each density, using the one you have as the "xxxhdpi one".
For example, let's say that image 300x450 is for a xhdpi screen. When you use that tool to create Image Asset, Android Studio will create a xxxhdpi asset 300x450, a xxhdpi 225x337, a xhdpi 150x225, and so on... And you try to use that xhdpi 150x225, in the same place you should use 300x450, and it pixels.
So, my solution, if you don't have the highest to generate the other ones, you should put that one directly in "xhdpi" (or the one it is designed for), and you can be sure that at least all density or lower than that, will be OK.
Just use scalable option in properties menu. in that select fitXY option and adjust your coordinates with height and width properties

Handling image resource size on Android

I am kind of confused about managing graphic resources in Android.
Tried to read this doc but It only confuses me more. Can anyone give me some example of how should I handle the following case?
Lets assume that I have an image in my layout that will be scaled to fill screen width. What image sizes (in pixels) should I produce and what configuration qualifiers (drawable-{qualifier}) should I apply to those resources to cover all major dpi and screen sizes (both for tablet and handset)?
Thanks.
If you want to have an image, that is supposed to fill the screen it is best to use 9-patch images. This way your image can automatically scale to fit the device. Because even if an image has the correct density, the actual screen size can vary. For example a smartphone and a tablet can both be hdpi, but have completely different screen sizes (and actual pixel count).
So the easiest way to target most devices, when it comes to images that are supposed to fill up the full width of the screen is to have a 9-patch image and create ldpi, mdpi, hdpi and xhdpi versions of it. This way the image will automatically be choosen depending on the density and then stretched to fit the device.
The android sdk also provides a tool that helps with creating 9-patch images http://developer.android.com/tools/help/draw9patch.html

Setting background image in Android for mdpi, ldpi, hdpi

I'm working on setting background image sized 320X480 jpg, for >= android 2.2 versions.
As per my understanding from previous posts related to mdpi,ldpi,hdpi & info from http://developer.android.com/guide/practices/screens_support.html , we can use image sized to
ldpi, the recommended size is 240x320.
mdpi, the recommended size is 320x480.
hdpi, the recommended size is 480x800
My question is, will the above mentioned sized images (in jpg format) work (or) should i have to create a single image generated using 9 patch placed in drawable/
and also i'm little confused in using jpg format for background, as i have seen many sample programs referring to png format, is that a standard or can we use any format ?
Any help would be really appreciated.
Thanks - Jitendar
The screensize doesn't have to be the ones you mentioned - it can be any other. Therefore better use a ninepatch to stretch the image properly. You should still provide different versions of those though, especially if you have parts of the image that don't stretch.
You can use either jpg or png...it does not matter...As for backroung image you can use an image that will have all sizes...just put it in corect folders and you will not have any problems...

How to use 9 patch images in android for different-2 densities(like mdpi,ldpi,hdpi).?

I am creating an android application in which I want multiple screen support.For these I have used 9 patch images.
But my question is this whether using 9 patch images will be enough for different-2 density's devices or I will need to create different-2 9 patch images for varying densities(like mdpi,ldpi,hdpi).
Thanks in advance
I recently found out myself in the same situation so let me pitch in and expand on what has been said already...
Yes, 9-patch images will scale, that's what they exist for. But if you should use a 9-patch image for all screen densities, that depends on the image really. 9-patch images are more commonly used, for instance, buttons. You can have different sized buttons in your app and a 9-patch image will help deal with them, no matter how you size your button (as long as the 9-patch image is properly created).
But let's say your button design has some really round corners for the hdpi version. You create your 9-patch image without messing the corners but when you look at it in the ldpi version, you'll realize your corners are too big for that low resolution. For this situation, you'll need a different 9-patch image with less round corners, that look better on that resolution.
So, the final answer is, it really depends on your image. If you can create a 9-patch image that looks good in all densities, than fine, use it, as you only need one image to handle all densities. But if it doesn't look good, because of corners, gradients, or whatever, than you'll need one 9-patch image for each screen density.
Hopefully it's clearer now.
From documentation: nine patch
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background. An example use of a NinePatch is the backgrounds used by standard Android buttons — buttons must stretch to accommodate strings of various lengths. A NinePatch drawable is a standard PNG image that includes an extra 1-pixel-wide border. It must be saved with the extension .9.png, and saved into the res/drawable/ directory of your project.
the answer is no. you nine patch will scale between different screen size
Short answer is YES.
Check this:
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate
physical size on each device. For example, if your application provides bitmap drawables only for
the baseline, medium screen density (mdpi), then the system scales them up when on a high-density
screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the
bitmaps. To ensure your bitmaps look their best, you should include alternative versions at
different resolutions for different screen densities.
from Android Developer Official Doc

Categories

Resources