Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

public class Main {
    public static Bitmap scaleBitmap(int maxWidth, int maxHeight, Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        float scale = 1;

        if (height > width) {
            if (height > maxHeight) {
                scale = (float) maxHeight / (float) height;
            }
        } else {
            if (width > maxWidth) {
                scale = (float) maxWidth / (float) width;
            }
        }

        width = (int) (width * scale);
        height = (int) (height * scale);

        return Bitmap.createScaledBitmap(bitmap, width, height, false);
    }
}