zoom Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

zoom Bitmap

Demo Code

import android.graphics.Bitmap;
import android.graphics.Matrix;

public class Main{

    public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {

        Matrix matrix = new Matrix();
        matrix.postScale(((float) width / bitmap.getWidth()),
                ((float) height / bitmap.getHeight()));
        Bitmap bitmapResized = Bitmap.createBitmap(bitmap, 0, 0,
                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return bitmapResized;

    }//from   ww  w . j ava2 s  .c  o m
    public static Bitmap zoomBitmap(Bitmap bitmap, int width) {

        Matrix matrix = new Matrix();
        matrix.postScale((float) width / bitmap.getWidth(), (float) width
                / bitmap.getWidth());
        Bitmap bitmapResized = Bitmap.createBitmap(bitmap, 0, 0,
                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return bitmapResized;

    }

    public static Bitmap zoomBitmap(Bitmap bitmap, int height,
            boolean forHeight) {

        Matrix matrix = new Matrix();
        matrix.postScale((float) height / bitmap.getHeight(),
                (float) height / bitmap.getHeight());
        Bitmap bitmapResized = Bitmap.createBitmap(bitmap, 0, 0,
                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return bitmapResized;

    }

    public static Bitmap zoomBitmap(Bitmap bitmap, float sacleF) {

        Matrix matrix = new Matrix();
        matrix.postScale(sacleF, sacleF);
        Bitmap bitmapResized = Bitmap.createBitmap(bitmap, 0, 0,
                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return bitmapResized;

    }

}

Related Tutorials