user590849
user590849

Reputation: 11765

resource size for different densities in android

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.

Upvotes: 1

Views: 1304

Answers (1)

SteD
SteD

Reputation: 14027

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.

Upvotes: 2

Related Questions