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 resize(Bitmap src, int max, boolean isKeep) {
        if (!isKeep)
            return resizeBitmap(src, max);

        int width = src.getWidth();
        int height = src.getHeight();
        float rate = 0.0f;

        if (width > height) {
            if (max > width) {
                rate = max / (float) width;
                height = (int) (height * rate);
                width = max;
            }
        } else {
            if (max > height) {
                rate = max / (float) height;
                width = (int) (width * rate);
                height = max;
            }
        }

        return Bitmap.createScaledBitmap(src, width, height, true);
    }

    public static Bitmap resizeBitmap(Bitmap src, int ratio) {
        if (src == null)
            return null;

        int width = src.getWidth();
        int height = src.getHeight();

        return Bitmap.createScaledBitmap(src, width * ratio, height * ratio, false);
    }
}