get New Resized Bitmap - Android Graphics

Android examples for Graphics:Bitmap Resize

Description

get New Resized Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap getNewResizedBitmap(Bitmap bm, int newHeight,
            int newWidth) {

        int width = bm.getWidth();

        int height = bm.getHeight();

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

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

        // create a matrix for the manipulation

        Matrix matrix = new Matrix();

        // resize the bit map

        matrix.postScale(scaleWidth, scaleHeight);

        // recreate the new Bitmap

        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
                matrix, false);/*from   w  w  w. j a  v a 2s.  com*/

        return resizedBitmap;

    }
}

Related Tutorials