List of usage examples for android.content.res Resources getValueForDensity
public void getValueForDensity(@AnyRes int id, int density, TypedValue outValue, boolean resolveRefs) throws NotFoundException
From source file:Main.java
public static Bitmap getBitmapForDensity(Resources res, int displayDpi, int resId) { try {//from ww w.j a va 2 s .c om TypedValue value = new TypedValue(); res.getValueForDensity(resId, displayDpi, value, true); AssetFileDescriptor fd = res.getAssets().openNonAssetFd(value.assetCookie, value.string.toString()); Options opt = new Options(); opt.inTargetDensity = displayDpi; Bitmap bitmap = BitmapFactory.decodeResourceStream(res, value, fd.createInputStream(), null, opt); bitmap.setDensity(res.getDisplayMetrics().densityDpi); fd.close(); return bitmap; } catch (Exception e) { return BitmapFactory.decodeResource(res, resId); } }