当前位置: 代码迷 >> Android >> Android Bit地图 改变大小
  详细解决方案

Android Bit地图 改变大小

热度:97   发布时间:2016-05-01 20:43:06.0
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. [email protected]of.?
  9. [email protected]'s?context.?
  10. ?????*?
  11. [email protected]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(0,?0,?FusionField.iconWidth,?FusionField.iconHeight);??
  52. ????????????sOldBounds.set(0,?0,?bitmapWidth,?bitmapHeight);??
  53. ????????????canvas.drawBitmap(bitmap,?sOldBounds,?sBounds,?paint);??
  54. ????????????return?thumb;??
  55. ????????}??
  56. ??
  57. ????????return?bitmap;??
  58. ????} ?
  相关解决方案