scale Bitmap To Pixel - Android Graphics

Android examples for Graphics:Bitmap Scale

Description

scale Bitmap To Pixel

Demo Code


//package com.java2s;

import android.content.Context;
import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    static public Bitmap scaleBitmapToPx(Context context, Bitmap bitmap,
            float dpX, float dpY) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        return scaleBitmap(bitmap, dpX / width, dpY / height);
    }/*from www  . j  a v  a 2s  .c o  m*/

    static public Bitmap scaleBitmap(Bitmap bitmap, float scaleX,
            float scaleY) {
        Matrix matrix = new Matrix();
        matrix.postScale(scaleX, scaleY);
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);
    }
}

Related Tutorials