Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bb4dade authored by Adam Koch's avatar Adam Koch
Browse files

Displaying Bitmaps Efficiently Training - Fix inSampleSize selection

When computing inSampleSize, calculateInSampleSize() needs to compare
height/width ratios, rather than raw values.

Bug: 7951398
Change-Id: I207f9abc2aae4cc569b406bac237e221d8e64d1e
parent cdf5106a
Loading
Loading
Loading
Loading
+31.7 KiB (420 KiB)

File changed.

No diff preview for this file type.

+10 −5
Original line number Diff line number Diff line
@@ -110,12 +110,17 @@ public static int calculateInSampleSize(
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = Math.round((float)height / (float)reqHeight);
        } else {
            inSampleSize = Math.round((float)width / (float)reqWidth);
        }

        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }

    return inSampleSize;
}
</pre>