/**
* 调整图片宽高比
*/
private Bitmap AdjustBitmapSize(ImageView iv, Bitmap bitmap) {
Bitmap resizeBmp;
// 获取控件的宽高
int width = bitmap.getWidth();
int height = bitmap.getHeight();
// 控件宽高比
float viewAspectRatio = ((float)iv.getWidth()) / iv.getHeight();
// 图片宽高比
float bitmapAspectRatio = ((float)bitmap.getWidth()) / bitmap.getHeight();
// 宽高比相等,直接使用
if (viewAspectRatio == bitmapAspectRatio) {
resizeBmp = bitmap;
}
// 控件宽高比大于图片宽高比,调整高度
else if (viewAspectRatio > bitmapAspectRatio) {
height = (int) (width / viewAspectRatio);
resizeBmp = Bitmap.createBitmap(width, height, Config.RGB_565);
Canvas canvas = new Canvas(resizeBmp);
Rect src = new Rect(0, (bitmap.getHeight() - height) / 2, bi
Bitmap切割图片(根据控件大小调整图片宽高比)-FenGKun
最新推荐文章于 2022-07-28 09:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)