Android中Bitmap按比例放大

2014-11-24 11:50:12 · 作者: · 浏览: 2

//把传进来的bitmap对象转换为宽度为x,长度为y的bitmap对象


public static Bitmap big(Bitmap b,float x,float y)
{
int w=b.getWidth();
int h=b.getHeight();
float sx=(float)x/w;//要强制转换,不转换我的在这总是死掉。
float sy=(float)y/h;

Matrix matrix = new Matrix();
matrix.postScale(sx, sy); // 长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(b, 0, 0, w,
h, matrix, true);
return resizeBmp;
}