Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;

public class Main {
    public static Bitmap createScaledToCenterInsideBitmap(Bitmap bitmap, int reqWidth, int reqHeight) {
        final int height = bitmap.getHeight();
        final int width = bitmap.getWidth();

        float widthScaleF = (float) width / (float) reqWidth;
        float heightScaleF = (float) height / (float) reqHeight;
        if (widthScaleF > heightScaleF) {
            return Bitmap.createScaledBitmap(bitmap, reqWidth, (int) (height / widthScaleF), true);
        } else {
            return Bitmap.createScaledBitmap(bitmap, (int) (width / heightScaleF), reqHeight, true);
        }
    }
}