From b547b5b9b15c3a7a73d694215eae5deb5141dd7c Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 29 Jan 2024 23:20:42 +0100 Subject: [PATCH] fixed aspect ratio when decoding TIFF with custom size --- .../deckers/thibault/aves/decoder/TiffGlideModule.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/decoder/TiffGlideModule.kt b/android/app/src/main/kotlin/deckers/thibault/aves/decoder/TiffGlideModule.kt index 4160bfd6e..c96631bf9 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/decoder/TiffGlideModule.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/decoder/TiffGlideModule.kt @@ -86,7 +86,17 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int if (bitmap == null) { callback.onLoadFailed(Exception("Decoding full TIFF yielded null bitmap")) } else if (customSize) { - callback.onDataReady(Bitmap.createScaledBitmap(bitmap, width, height, true)) + val dstWidth: Int + val dstHeight: Int + val aspectRatio = bitmap.width.toFloat() / bitmap.height + if (aspectRatio > 1) { + dstWidth = (height * aspectRatio).toInt() + dstHeight = height + } else { + dstWidth = width + dstHeight = (width / aspectRatio).toInt() + } + callback.onDataReady(Bitmap.createScaledBitmap(bitmap, dstWidth, dstHeight, true)) } else { callback.onDataReady(bitmap) }