Fix portrait image resizing on Android

This commit is contained in:
Florian Rival 2016-06-14 12:22:49 +02:00
parent d0ffb34194
commit b664dfe510
1 changed files with 8 additions and 13 deletions

View File

@ -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);
} }