歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中Bitmap按比例放大

Android中Bitmap按比例放大

日期:2017/3/1 10:16:54   编辑:Linux編程

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;
}

Copyright © Linux教程網 All Rights Reserved