0

I want to use the PNG format of my Android studio drawable logo in splash-screen for APIs 21 and 22. As it has been noted in this post, these APIs have problems with drawables in layer-list. So I want to convert my drawable file into a PNG format file (using Adobe AI or CorelDraw, etc), but I don't know exactly what dimensions I should save my file to match exactly with Android drawable dp.

My drawable logo size is 100dp x 100dp. What dimensions should I export my file to? Is that just one file, or should I export 5 different sizes for idp, mdp, xdp, xxdp and xxxdp? I am aware that layer-list doesn't support @mipmap resource.

Here is a programmatic way that provides the following unit-conversion formula

pixels = dps * (density / 160)

But do I have to have a PNG file for each density?

Update: I tried to use the above formula or online unit-convertors but the result was so bigger that what I expedted. for my logo that is 100*100 dp*pd I created a PNG format logo with dimensions 187.5*187.5 px*px and with dpi 300, that was bigger that 100*100 dp*pd!

2 Answers2

2

As you can see from the formula you quoted, the number of pixels is dependent on the density of the display.

So, if you want to match your image size in pixels exactly to the dps, then you would need a separate image for each density.

I'm not saying that doing this is necessarily a good or bad idea, just answering exactly what you asked.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • What if I set my image unit in `mm` or `in` that are independent from `dpi` I think. then it will match with original one? I tried this but again the result size was big. – user21193451 Jul 14 '23 at 04:21
1

The following is what I've asked from AI. That is cool:

To export a PNG bitmap that matches exactly with the Android 72dp for the mdpi density, you need to consider the pixel size and dots per inch (dpi) values. Here's how you can calculate the required values:

Determine the baseline density: The baseline density for Android is mdpi, which has a density of 160 dpi. This means that 1 dp is equal to 1 pixel at mdpi density.

Calculate the pixel size: To match the Android 72dp, you need to calculate the corresponding pixel size. Since 1 dp is equal to 1 pixel at mdpi density, the pixel size for 72dp would be 72 pixels.

Calculate the dpi value: To determine the dpi value for the mdpi density, you can use the following formula:

dpi = (pixel size * 160) / dp size

In this case, the pixel size is 72 pixels, and the dp size is 72 dp. Plugging these values into the formula, we get:

dpi = (72 * 160) / 72 = 160 dpi

Therefore, to match exactly with the Android 72dp at mdpi density, you should export the PNG bitmap with a pixel size of 72 pixels and a dpi value of 160 dpi.

C.F.G
  • 817
  • 8
  • 16