天天看点

Android中Bitmap按比例放大

    其实这个很简单,但是不知道,怎么啦,我写了好几次都出现了异常。最后终于写好了。

     //把传进来的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;

 }