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;

public class Main {
    public static Bitmap scaleBitmap(Bitmap srcBmp, int iWidth, int iHeight) {
        float fWidth = srcBmp.getWidth();
        float fHeight = srcBmp.getHeight();

        if (fWidth > iWidth) {
            float mWidth = (float) (fWidth / 100);
            float fScale = (float) (iWidth / mWidth);
            fWidth *= (fScale / 100);
            fHeight *= (fScale / 100);
        } else if (fHeight > iHeight) {
            float mHeight = (float) (fHeight / 100);
            float fScale = (float) (iHeight / mHeight);
            fWidth *= (fScale / 100);
            fHeight *= (fScale / 100);
        }
        return Bitmap.createScaledBitmap(srcBmp, (int) fWidth, (int) fHeight, true);
    }
}