How to determine which bitmap resource was downloaded (ldpi, mdpi or hdpi)?

I created several raster images - one for each folder (mdpi, hdpi, ldpi). Can someone show me some code or tell me the appropriate method that will allow me to determine which Android resource I decided to download.

Thank,

+3
source share
4 answers

This is available in the bitmap itself - http://developer.android.com/reference/android/graphics/Bitmap.html#getDensity ()

Resource.getDrawable() API, , Drawable. , ( ), BitmapDrawable .

, , , (, drawable -nodpi). , . , , .:)

+2

DPI DisplayMetric .

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

switch(metrics.densityDpi)
{
case DisplayMetrics.DENSITY_HIGH: //HDPI
case DisplayMetrics.DENSITY_LOW:  //LDPI
case DisplayMetrics.DENSITY_MEDIUM: //MDPI
}
+4

, , resolution.png, ldpi, "l", mdpi "m" , hdpi "h". , .

, , .

+1

Bitmap :

Access to resources can be obtained in the form of raw data: use AssetManager.open (..) Then you can use BitmapFactory.decodeStream (..) to create a bitmap image from the data stream.

0
source

Source: https://habr.com/ru/post/1774824/


All Articles