How to scale down image for multiple screens? - android

If I have an image 240 by 240 pixels designed in Adobe Illustrator (for example) at 240 dots per inch for high density screens, what would be the best way to save a version of this image for medium density screens? Should I keep the image at 240 by 240 pixels and reduce the dots per inch to 160? Or keep the image at 240 dots per inch and shrink it to 160 by 160 pixels? Or some other variation?!

AFAIK DPI is ignored, it's only relevant for printing where it tells the printer how many pixels to print per inch, there is always exactly one screen pixel per bitmap pixel*, so as the other comment suggests, you just need to scale the image using the ratios 3:4:6:8.
*Essentially, anyway.

Related

Android - How does dp occupy different space in devices with different sizes?

I searched a lot about dp, px, inch, pt etc.
From what I understood about 'dp':
Specifying 'dp' is simply a way to make Android draw the views with same size for devices with different screen densities. Eg, for a medium density device, each 'dp' will occupy a pixel. For a high density device - which has smaller pixels to fit more pixels per inch, 'dp' will occupy more than a pixel. For a low density device - which has larger pixels to fit less pixels per inch, 'dp' will occupy less than a pixel.
But what I also read is that space occupied by a 'dp' varies according to screen sizes, i.e for a small screen a 'dp' will occupy less space, while for a larger screen a 'dp' will occupy larger space.
How exactly does this happen? From what I understood about 'dp', it should occupy the same amount of space in devices with differing screen sizes. Eg, a large screen of 240 dpi will have a 'dp' occupy 1.5 pixels, and so will be the case for a small screen of 240 dpi. Then how is it that a 'dp' will occupy different amount of space for different screen sizes?
What am I missing in my understanding of 'dp'? Please help.
Android defines a baseline dpi of 160 which is used as the reference to compute sizes for all screen densities:
pixel_size * (device_dpi / baseline_dpi) = result in "dp" units
>> or the other way around
dp_size / (device_dpi / baseline_dpi) = result in "pixel" units
Therefore, 1 pixel in a 240dpi device is equivalent to 1.5dp units:
1 * (240 / 160) = 1.5
and the other way around, 1.5dp units in a 240dpi device is equivalent to 1 pixel
1.5 / (240 / 160) = 1
The important fact to know is that 160 is the baseline used as the reference for all DPIs.
So, as dp units increase/decrease, the required pixels area to draw something translates into keeping the same size scale regardless of the device screen.
More information in the official documentation.
To be more clear:
The display size is not related to "dp units". The display size is just how big the display canvas is. The screen DPI defines how many dots fit in 1 square inch. And a "dp unit" is an abstract unit that, depending on the device's DPI, is scaled (up or down) to give "uniform dimensions" on any screen size, by using 160 as the baseline reference.
on the Android operating system a device-independent pixel is equivalent to one physical pixel on a 160 dpi screen. By this definition, you can understanddp has no relation with screen sizes as the scale is already fixed as 160 dpi.
.

Confusion about Resolution, Screen aspects in Android

I'm asking this question after much reading. I've always heard that dpi is for printers, but when it comes to screen now, they are also talking about dpi. Are they referring to ppi?
Now, what is really resolution, for me its the the number of pixels each dimension can display, e.g. 800x600 means 800 pixesl on width and 600 pixels on the height, but at some places I'm seeing that they are referring to resolution as dpi.
I'm trying to understand this concept well because its very important in Android, like in this article,
For example, say an icon is intended to be 0.5x0.5 in when rendered on a screen. Next, the image must be created at the largest density supported, or as a scalable vector graphic. Best practice is to support the maximum density, which currently is xxhdpi at 480 dpi. At 480 dpi, a 0.5x0.5 in image converts to 240x240 px.
So it is referring dpi as ppi actually if I understand?
So far what I've understood is that different pixels may render different number of pixels. This is why we don't use pixels as measurement unit. Instead we use dp, where a dp is one pixel on 160 dpi device (again the confusion about dpi & ppi)
Can someone clear this big confusion or direct me to an article that may clear it
Mate, Resolution being 800 X 600 implies that the screen has 480,000 pixel points that will be used to render the screen(This is often confused with the dimensions of the display). DPI or PPI means dots/points per inch, this is the measure of the density of the screen.
So just given the Resolution, one can not determine the actual length of the display unless the density parameter is also available. So a 800 X 600 resolution has 480,000 Pixel points & a let this device has a density of 480 dpi.
So the Width of the screen
= No of pixel points along its width/Density
= 800/480
= 1.67 inches
Similarly,
Height = 600/480
=1.25 inches
and if 800X600 resolution device has density of 160 dpi, its dimensions will vary drastically. Following calculations calculate Height/Width of 800X600 on 160 dpi. Compare these two values with above 480 dpi calculations.
the Width of the screen
= No of pixel points along its width/Density
= 800/160
= 5.0 inches
Similarly,
Height = 600/160
=3.75 inches
This is the very reason that scaling images to best fit the screen is such a complex issue on frafmented android environment.However, I love android!
Hope this helps!
and any one who has some thing to add/delete.modify to this answer is most welcome.
dpi (dots per inch) == ppi (pixels per inch)
You are also talking about the DisplayMetrics.density, which gives you the multiplier for the dp unit of measurement.
There's also DisplayMetrics.scaledDensity which also takes into account text size user chose.
To put it plainly, dp unit is intended to give you some security about size of your objects on screen. 160dp should represent one inch on any screen. In order to achieve that, you have to multiply your dimension by DisplayMetrics.density or DisplayMetrics.scaledDensity.
That is, if you're doing that in code. For Layouts, you can just enter a View's dimensions in dp and have Android framework take care of that for you.

How should i know the phone that has the specified arguments is the hdpi or ldpi

As the titles,the following is some arguments of the psd of my phone:
The width pixels:
The height pixels:
The width of document is:13.333 inch
The height of document is :7.5 inch
so the dpi will be 96,and we will know the phone is just a ldpi phone as the http://developer.android.com/guide/practices/screens_support.html
can anyone tell me whether it is right or not.
If your graphics are designed to display at 96 pixels/inch, then they are not a good match for Android. The minimum density devices are nominally 120 pixels/inch (called LDPI). If you put your graphics in res/drawable-ldpi, they will appear about 96/120 (or about 3/4) their original size (in inches).
If the images are displayed on a higher density device, Android will automatically scale the images up, so they will keep this size ratio regardless of actual device pixel density.
The only way to fix this is to rescale your images before adding them to yuor project. You will get the best quality if you rescale to each of the nominal pixel densities (120, 160, 240, and 320; you could also throw in 213 for tvdpi screens).

How do I know how much DPI the device has?

How do I know how much DPIs a device has (and thus if it's ldpi / mdpi / hdpi / xhdpi, - and screen size, which is also measured in dp - xlarge / large / normal / small - according to http://developer.android.com/guide/practices/screens_support.html)?
I know the device's resolution and diagonal size, for example:
Display TFT LCD, 3.5 in (89 mm) diagonal.
320×480 px HVGA with Gorilla Glass
16M colors
(Taken from http://en.wikipedia.org/wiki/Samsung_Galaxy_Ace)
Don't need it programmatically, just to calculate myself.
Use DPI calculator to calculate dpis, and Figure 1 in the dev docs to determine whether its ldpi, mdpi, etc.
I think DPI reffers to printers... IN your case DPI = PPI. Please correct me if i'm wrong [edit: I'm wrong :P]
'So a 1200 dpi printer uses 1200 dots of ink in every inch to make up the colours. If you were printing a 300 PPI image, then every pixel would be made up of 16 smaller ink dots (1200 DPI x 1200 DPI / 300 PPI x 300 PPI). A lower DPI would have fewer ink dots making up each pixel, which would make the colour look worse. A higher DPI would have more ink dots for each pixel and should give more accurate colour (especially under close examination).'

Android DPI - a lie?

So I create sets of assets for an Android UI - 320 x 400 & 480 x 800 both of these at 160 and 240 dpi...
After Drawing some of the assets as 9 patch a weird thing happened. The 9 patch graphics all 'came out' as 72 dpi but with different dimensions!
So my conclusion is that android asset creation works similiar to iPhone. Creatings assets to dimensions and ignore DPI (using 72 as a base - as this is what the 9 patch programme converted them too!) RIGHT?
Anyone else experimented with this?
Just think for a minute about what DPI is. Dots per Inch. For displays, it's actually Pixels per Inch, or PPI.
A 320 pixel wide image at 160 pixels per inch is 320 pixels wide. How many pixels wide is a 320 pixel image at 240 pixels? The PPI density only matters on the actual output device. Your display has a fixed number of pixels at a fixed physical size. The number of pixels that fit into 1 inch is its PPI density. The reason this is modifiable for graphics is for when the density can differ. Most commonly, this is for printing (which is where the dots come in). Most printers can print at a variety of resolutions. The typical is something like 300 dpi for images, 1200 dpi or higher for vector graphics and line art. When you set the dpi before printing an image, it tells the printer how many dots per inch it should lay out. The higher the dpi, the sharper the image -- assuming the input image is actually large enough to accomodate this resolution.

Categories

Resources