According to Google's iconography , I added my application icon (ic_launcher) in multiple densities. And it works correctly. But how can I programmatically get the icon in code?
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
Usually I use this code, but I always decode an image of 64x64 dimension which none of my original icons has. How can I force the BitmapFactory to decode for instance XXXHPDI ?
从API级别15开始,您可以在此处使用以下方法:
getResources().getDrawableForDensity(id, density);
try this,
BitmapFactory.Options options = new BitmapFactory.Options();// whichever you want to load
options.inDensity = DisplayMetrics.DENSITY_MEDIUM;
options.inTargetDensity = getResources().getDisplayMetrics().densityDpi;
options.inScaled = true;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.