private Bitmap prepare(final Bitmap map) { int dstW = request.getRequiredWidth(), dstH = request.getRequiredHeight(); if (dstW <= 0 || dstH <= 0 || request.isSkipScaleBeforeMemCache()) { if (imagesManager.debug) { Log.d( TAG, "Skip scaling for " + request.getKey() + " skip flag: " + request.isSkipScaleBeforeMemCache()); } return map; } final int w = map.getWidth(), h = map.getHeight(); if (w <= dstW && h <= dstH) { return map; } final double ratio = (double) w / h; if (w > h) { dstH = (int) (dstW / ratio); } else { dstW = (int) (dstH * ratio); } if (dstW <= 0 || dstH <= 0) { return map; } final Bitmap scaled = Bitmap.createScaledBitmap(map, dstW, dstH, true); scaled.setDensity(imagesManager.getResources().getDisplayMetrics().densityDpi); return scaled; }