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;

public class Main {
    public static Bitmap ResizeBitmap(Bitmap bitmap, int newWidth) {

        int width = bitmap.getWidth();

        int height = bitmap.getHeight();

        float temp = ((float) height) / ((float) width);

        int newHeight = (int) ((newWidth) * temp);

        float scaleWidth = ((float) newWidth) / width;

        float scaleHeight = ((float) newHeight) / height;

        Matrix matrix = new Matrix();

        // resize the bit map

        matrix.postScale(scaleWidth, scaleHeight);

        //         matrix.postRotate(90);

        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

        bitmap.recycle();

        return resizedBitmap;

    }
}