zoom Bitmap by width and height - Android Graphics

Android examples for Graphics:Bitmap Zoom

Description

zoom Bitmap by width and height

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {

    public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {

        if (bitmap == null) {
            return null;
        }/*from  w  ww  .j  av a 2  s.c om*/

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        Matrix matrix = new Matrix();

        float scaleWidht = ((float) w / width);
        float scaleHeight = ((float) h / height);

        matrix.postScale(scaleWidht, scaleHeight);

        Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
                matrix, true);

        return newbmp;
    }
}

Related Tutorials