Assume you know how to downscale Bitmap
. So you just need to know to which size you should downscale certain image. You could use something like this to determine the device screen size (usually I do it in Application
class):
displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
displayDensity = displayMetrics.densityDpi;
displayHeight = displayMetrics.heightPixels;
displayWidth = displayMetrics.widthPixels;
Now its up to you to decide what is the max image size your app will allow accorrding to displayHeight
and displayWidth
values.
If you want to show your images full screen you could set max image side size as displayHeight
/2 (actually you should determine the biggest screen side size and for smartphones its usually the height).
If you want to display some previews in a list, you should limit preview's image side size to something like displayWidth
/3 (once again you should determine the smallest screen dimension and for smartphones its a width usually).
I have a method like this (to determine a max allowed ListView image side size in px):
public static int getDeviceMaxSideSizeByDensity(){
int maxSideSize=128;
if (isHiResDisplay!=null)
{
switch (displayDensity) {
case 120:
maxSideSize = 64;
break;
case 160:
maxSideSize = 96;
break;
case 240:
maxSideSize = 128;
break;
case 320:
maxSideSize = 256;
break;
default:
maxSideSize = 512;
break;
}
}
return maxSideSize;
}
you could set other values, bigger or smaller, its up to you once again.
I suggest you to use a lib like Glide (Picasso, Fresco, UIL) to get rid of such minds. Let the lib to decide.