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;

import android.graphics.Matrix;

public class Main {
    /**
     * Shrink the bitmap to the specified scale.
     *
     * @param bitmap to shrink.
     * @param scale  the shrink scale, must be < 1.0.
     * @return the shrunk bitmap.
     */
    public static Bitmap shrink(Bitmap bitmap, float scale) {
        if (scale >= 1.0f) {
            return bitmap.copy(bitmap.getConfig(), false);
        }

        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale);

        return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()),
                (int) (scale * bitmap.getHeight()), matrix, true);
    }
}