读书人

Bit地图缩放的一个方法

发布时间: 2012-08-26 16:48:05 作者: rapoo

Bitmap缩放的一个方法
public static Bitmap bitmapRoom(Bitmap srcBitmap,int newHeight,int newWidth)
{
int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();

float scaleWidth = ((float) newWidth) / srcWidth;
float scaleHeight = ((float) newHeight) / srcHeight;

Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth,
srcHeight, matrix, true);
if(resizedBitmap != null)
{
return resizedBitmap;
}
else
{
return srcBitmap;
}

}


读书人网 >移动开发

热点推荐