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.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable scaleImage(Drawable drawable, float scaleWidth, float scaleHeight) {
        Drawable resizedDrawable = null;
        if (drawable != null) {
            Bitmap bitmapOrg = ((BitmapDrawable) drawable).getBitmap();
            int width = bitmapOrg.getWidth();
            int height = bitmapOrg.getHeight();

            Matrix matrix = new Matrix();

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

            resizedDrawable = new BitmapDrawable(resizedBitmap);
        }
        return resizedDrawable;
    }
}