Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

import android.util.Log;

public class Main {
    public static Bitmap createResizedBitmap(Bitmap srcBit, int newWidth, int newHeight) {
        int width = srcBit.getWidth();
        int height = srcBit.getHeight();

        // calculate the scale - in this case = 0.4f
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;

        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap resizedBitmap = Bitmap.createBitmap(srcBit, 0, 0, width, height, matrix, true);

        width = resizedBitmap.getWidth();
        height = resizedBitmap.getHeight();

        Log.i("ImageResize",
                "Image Resize Result : " + Boolean.toString((newHeight == height) && (newWidth == width)));
        return resizedBitmap;
    }
}