Create Squared Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

Create Squared Bitmap

Demo Code

import android.graphics.Bitmap;

public class Main {

  public static Bitmap getSquareBitmap(Bitmap bitmap) {
    Bitmap output;/*  w w  w. j  a  v a  2  s.  com*/
    if (bitmap.getWidth() >= bitmap.getHeight())
      output = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 2 - bitmap.getHeight() / 2, 0, bitmap.getHeight(),
          bitmap.getHeight());
    else
      output = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 2 - bitmap.getWidth() / 2, bitmap.getWidth(),
          bitmap.getWidth());
    return output;
  }

}

Related Tutorials