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 {

    public static Bitmap scaleBitmap(Bitmap bitmap, int reW, int reH) {
        if (bitmap == null) {
            return null;
        }
        int bmpW = bitmap.getWidth();
        int bmpH = bitmap.getHeight();
        float wScale = reW * 1.0f / bmpW;
        float hScale = reH * 1.0f / bmpH;
        float scale = Math.max(wScale, hScale);
        Matrix matrix = new Matrix();
        matrix.setScale(scale, scale);
        return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrix, true);
    }
}