Android Bitmap 改变大小

/**
* Returns a Bitmap representing the thumbnail of the specified Bitmap.
* The size of the thumbnail is defined by the dimension
* android.R.dimen.launcher_application_icon_size.
*
* This method is not thread-safe and should be invoked on the UI thread only.
*
* @param bitmap The bitmap to get a thumbnail of.
* @param context The application's context.
*
* @return A thumbnail for the specified bitmap or the bitmap itself if the
* thumbnail could not be created.
*/
public static Bitmap createBitmapThumbnail(Bitmap bitmap, Context context)
{
if(FusionField.iconWidth == -1&&(FusionField.screenWidth == 800 && FusionField.screenHeight == 480)){
FusionField.iconWidth = 80;
FusionField.iconHeight = 98;

}
else if (FusionField.iconWidth == -1)
{
FusionField.iconWidth = 60;
FusionField.iconHeight = 82;
}

final int bitmapWidth = bitmap.getWidth();
final int bitmapHeight = bitmap.getHeight();

Log.e("dean xiang", "" + bitmapWidth + ":" + bitmapHeight);
if (FusionField.iconWidth > 0 && FusionField.iconHeight > 0)
{

final Bitmap.Config c = Bitmap.Config.ARGB_8888;
final Bitmap thumb = Bitmap
.createBitmap(FusionField.iconWidth, FusionField.iconHeight, c);
final Canvas canvas = sCanvas;
final Paint paint = sPaint;

canvas.setBitmap(thumb);
paint.setDither(false);
paint.setFilterBitmap(true);
// int offsetX = Math.abs(sIconWidth - bitmapWidth) / 2;
// int offsetY = Math.abs(sIconHeight - bitmapHeight) / 2;
//
// sBounds.set(offsetX, offsetY, bitmapWidth + offsetX,
// bitmapHeight + offsetY);
// sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
// canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);

sBounds.set(0, 0, FusionField.iconWidth, FusionField.iconHeight);
sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
return thumb;
}

return bitmap;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值