Android Bitmap 改变大小

  1. /** 
  2.      * Returns a Bitmap representing the thumbnail of the specified Bitmap. 
  3.      * The size of the thumbnail is defined by the dimension 
  4.      * android.R.dimen.launcher_application_icon_size. 
  5.      * 
  6.      * This method is not thread-safe and should be invoked on the UI thread only. 
  7.      * 
  8.      * @param bitmap The bitmap to get a thumbnail of. 
  9.      * @param context The application's context. 
  10.      * 
  11.      * @return A thumbnail for the specified bitmap or the bitmap itself if the 
  12.      *         thumbnail could not be created. 
  13.      */  
  14.     public static Bitmap createBitmapThumbnail(Bitmap bitmap, Context context)  
  15.     {  
  16.          if(FusionField.iconWidth == -1&&(FusionField.screenWidth == 800 && FusionField.screenHeight == 480)){  
  17.                 FusionField.iconWidth = 80;  
  18.                 FusionField.iconHeight = 98;  
  19.               
  20.         }  
  21.         else if (FusionField.iconWidth == -1)  
  22.         {  
  23.                 FusionField.iconWidth = 60;  
  24.                 FusionField.iconHeight = 82;  
  25.         }  
  26.   
  27.         final int bitmapWidth = bitmap.getWidth();  
  28.         final int bitmapHeight = bitmap.getHeight();  
  29.   
  30.         Log.e("dean xiang""" + bitmapWidth + ":" + bitmapHeight);  
  31.         if (FusionField.iconWidth > 0 && FusionField.iconHeight > 0)  
  32.         {  
  33.   
  34.             final Bitmap.Config c = Bitmap.Config.ARGB_8888;  
  35.             final Bitmap thumb = Bitmap  
  36.                     .createBitmap(FusionField.iconWidth, FusionField.iconHeight, c);  
  37.             final Canvas canvas = sCanvas;  
  38.             final Paint paint = sPaint;  
  39.   
  40.             canvas.setBitmap(thumb);  
  41.             paint.setDither(false);  
  42.             paint.setFilterBitmap(true);  
  43.             //          int offsetX = Math.abs(sIconWidth - bitmapWidth) / 2;  
  44.             //          int offsetY = Math.abs(sIconHeight - bitmapHeight) / 2;  
  45.             //            
  46.             //          sBounds.set(offsetX, offsetY, bitmapWidth + offsetX,  
  47.             //                  bitmapHeight + offsetY);  
  48.             //          sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);  
  49.             //          canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);  
  50.               
  51.             sBounds.set(00, FusionField.iconWidth, FusionField.iconHeight);  
  52.             sOldBounds.set(00, bitmapWidth, bitmapHeight);  
  53.             canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);  
  54.             return thumb;  
  55.         }  
  56.   
  57.         return bitmap;  
  58.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值