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 {
    public static Bitmap resizePreservingRatio(Bitmap original, int newWidth, int newHeight) {
        if (original == null)
            return null;

        int originalWidth = original.getWidth();
        int originalHeight = original.getHeight();

        if (newWidth / (float) originalWidth < newHeight / (float) originalHeight) {
            newHeight = originalHeight * newWidth / originalWidth;
        } else {
            newWidth = originalWidth * newHeight / originalHeight;
        }

        return Bitmap.createScaledBitmap(original, newWidth, newHeight, true);
    }
}