Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

public class Main {
    /**
     * center crop to target size.
     */
    public static Bitmap centerCropBitmap(Bitmap srcBmp, int destSize) {
        int srcWidth = srcBmp.getWidth();
        int srcHeight = srcBmp.getHeight();
        if (srcWidth >= srcHeight) {
            destSize = destSize <= srcHeight ? destSize : srcHeight;
        } else {
            destSize = destSize <= srcWidth ? destSize : srcWidth;
        }
        return Bitmap.createBitmap(srcBmp, srcWidth / 2 - destSize / 2, srcHeight / 2 - destSize / 2, destSize,
                destSize);
    }
}