android bitmap缩放失真,Android处理Bitmap使其能够不失真等比缩放裁剪后显示在ImageView上...

该代码段展示了如何根据ImageView的尺寸,创建并返回适应的Bitmap对象。通过比较Bitmap原始尺寸与目标尺寸,分别调用不同的方法进行缩放裁剪,确保Bitmap在ImageView中正确显示。主要涉及Bitmap的缩放和裁剪操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值