adaptive scale Bitmap - Android Graphics

Android examples for Graphics:Bitmap Scale

Description

adaptive scale Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap adaptive(Bitmap bitmap, int scalX, int scalY) {
        Matrix matrix = new Matrix();
        int width = bitmap.getWidth();// ????????????
        int height = bitmap.getHeight();// ????????????
        float w = (float) scalX / bitmap.getWidth();
        float h = (float) scalY / bitmap.getHeight();
        matrix.postScale(w, h);//w  ww  . j  a  va2 s  . c o  m
        Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
                matrix, true);
        return newbmp;
    }
}

Related Tutorials