resource size for different densities in android

1.3k Views Asked by At

i have made images for an mdpi phone in android. i want to resize those images for hdpi and ldpi screens. what is the conversion factor for the dimesions? i have heard that we multiply the height and width of the mdpi image by 1.5 to convert it to a hdpi screen. what is the accurate conversion factor- for both mdpi to hpdi and mdpi to ldpi? thank you in advance.

1

There are 1 best solutions below

0
On

From the Android developer, 0.75 for ldpi, 1.0 for mdpi and 1.5 for hdpi. Note that if you specified the measurements in dp ( density-independent pixels ), Android will take care of the scaling for you.

It scales 1.5 times if the target density is high density (160->240 virtual dpi), or 0.75 times if the target density is low density (160 -> 120 virtual dpi).

You could also scale it in the coding, by retrieving the current density and multiply them.

float scale = getContext().getResources().getDisplayMetrics().density; // retrieve current density

newImageWidth = currentImageWidth * scale;

This is a good read regarding density.