center Crop Bitmap - Android Graphics

Android examples for Graphics:Bitmap Crop

Description

center Crop Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

public class Main {
    public static Bitmap centerCrop(Bitmap srcBmp) {
        Bitmap dstBmp;//from  w  w  w .  j  a  v  a2s.  c  o  m
        if (srcBmp.getWidth() >= srcBmp.getHeight()) {

            dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2
                    - srcBmp.getHeight() / 2, 0, srcBmp.getHeight(),
                    srcBmp.getHeight());

        } else {

            dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2
                    - srcBmp.getWidth() / 2, srcBmp.getWidth(),
                    srcBmp.getWidth());
        }
        return dstBmp;
    }
}

Related Tutorials