Friday, August 3, 2012

Android scale a Bitmap function


public static Bitmap getResizeBitmap (Bitmap img, int newWidth, int newHeight) {
double ratio = newWidth / img.getWidth();
ratio = (newHeight / img.getHeight()) < ratio ? (newHeight / img.getHeight()) : ratio;
Bitmap b2 = Bitmap.createScaledBitmap(img, (int) (img.getWidth() * ratio), (int) (img.getHeight() * ratio), true);
return b2;
}