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;

import android.graphics.Matrix;

public class Main {
    public static Bitmap scaleBitmap(Bitmap srcBitmap, int newSize) {
        int w = srcBitmap.getWidth();
        int h = srcBitmap.getHeight();

        // Determine the scaling required to get desired result.
        float scaleW = newSize / (float) w;
        float scaleH = newSize / (float) h;

        Matrix matrix = new Matrix();
        matrix.postScale(scaleW, scaleH);

        return Bitmap.createBitmap(srcBitmap, 0, 0, w, h, matrix, false);
    }
}