Fix portrait image resizing on Android
This commit is contained in:
parent
d0ffb34194
commit
b664dfe510
|
@ -37,18 +37,13 @@ class ImageResizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxHeight > 0 && maxWidth > 0) {
|
if (maxHeight > 0 && maxWidth > 0) {
|
||||||
int width = image.getWidth();
|
float width = image.getWidth();
|
||||||
int height = image.getHeight();
|
float height = image.getHeight();
|
||||||
float ratioBitmap = (float) width / (float) height;
|
|
||||||
float ratioMax = (float) maxWidth / (float) maxHeight;
|
|
||||||
|
|
||||||
int finalWidth = maxWidth;
|
float ratio = Math.min((float)maxWidth / width, (float)maxHeight / height);
|
||||||
int finalHeight = maxHeight;
|
|
||||||
if (ratioMax > 1) {
|
int finalWidth = (int) (width * ratio);
|
||||||
finalWidth = (int) ((float) maxHeight * ratioBitmap);
|
int finalHeight = (int) (height * ratio);
|
||||||
} else {
|
|
||||||
finalHeight = (int) ((float) maxWidth / ratioBitmap);
|
|
||||||
}
|
|
||||||
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
|
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue