Resize a Bitmap by height - Android android.graphics

Android examples for android.graphics:Bitmap Size

Description

Resize a Bitmap by height

Demo Code

import android.graphics.Bitmap;
import android.graphics.Matrix;

public class Main {

  public static Bitmap getResizedBitmap(Bitmap bm, int newHeight) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleHeight * 1.2f, scaleHeight);

    // "RECREATE" THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
  }//from w ww .j  a va 2  s .  c o  m

}

Related Tutorials