1 /**

2 * 获取正确缩放裁剪适应IamgeView的Bitmap3 *@paramimageView4 *@parambitmap5 *@return

6 */

7 public staticBitmap createFitBitmap(ImageView imageView, Bitmap bitmap) {8 Log.i(TAG, "createFitBitmap= widthTarget && heightBitmap >=heightTarget ){19 result =createLargeToSmallBitmap(widthBitmap, heightBitmap, widthTarget, heightTarget, bitmap);20 }21 else if( widthBitmap >= widthTarget && heightBitmap =heightTarget ){26 Bitmap temp =createLargeHeightToEqualWidthBitmap(widthBitmap, heightBitmap, widthTarget, heightTarget, bitmap);27 result =createLargeToSmallBitmap(temp.getWidth(), temp.getHeight(), widthTarget, heightTarget, temp);28 }29 else{30 Bitmap temp =createSmallToEqualBitmap(widthBitmap, heightBitmap, widthTarget, heightTarget, bitmap);31 result =createFitBitmap(imageView, temp);32 }33 Log.i(TAG, "createFitBitmap--------------------->");34 returnresult;35 }36

37

38

39 private static Bitmap createLargeToSmallBitmap( int widthBitmap, int heightBitmap, int widthTarget, intheightTarget, Bitmap bitmap){40 Log.i(TAG, "createLargeToSmallBitmap");48 returnBitmap.createBitmap(bitmap, x, y, widthTarget, heightTarget);49 }50

51 private static Bitmap createLargeWidthToEqualHeightBitmap(int widthBitmap, int heightBitmap, int widthTarget, intheightTarget, Bitmap bitmap){52

53 Log.i(TAG, "createLargeWidthToEqualHeightBitmap");60 return Bitmap.createScaledBitmap(bitmap, (int)(widthBitmap * scale) , heightTarget, false);61 }62

63 private static Bitmap createLargeHeightToEqualWidthBitmap(int widthBitmap, int heightBitmap, int widthTarget, intheightTarget, Bitmap bitmap){64

65 Log.i(TAG, "createLargeHeightToEqualWidthBitmap");72 return Bitmap.createScaledBitmap(bitmap, widthTarget , (int)(heightTarget * scale), false);73 }74

75 private static Bitmap createSmallToEqualBitmap(int widthBitmap, int heightBitmap, int widthTarget, intheightTarget, Bitmap bitmap){76

77 Log.i(TAG, "createSmallToEqualBitmap");86 return Bitmap.createScaledBitmap(bitmap, (int)(widthBitmap * scale), (int)(heightBitmap * scale), false);87 }

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐