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 {
    /** Returns a scaled version of the given Bitmap. One of the returned Bitmap's width and height will be equal to size, and the other
     * dimension will be equal or less.
     */
    public static Bitmap createScaledBitmap(Bitmap bitmap, int size) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int scaledWidth = size, scaledHeight = size;
        if (height < width) {
            scaledHeight = (int) (size * 1.0f * height / width);
        } else if (width < height) {
            scaledWidth = (int) (size * 1.0f * width / height);
        }
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);
        return scaledBitmap;
    }
}