android bitmap缩放失真,Android处理Bitmap使其能够不失真等比缩放裁剪后显示在ImageView上...
1 /**2 * 获取正确缩放裁剪适应IamgeView的Bitmap3 *@paramimageView4 *@parambitmap5 *@return6*/7public staticBitmap createFitBitmap(ImageView imageView, Bitmap bitmap) {8Log.i(TAG, "createFitBit...
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 }
更多推荐
所有评论(0)