Skip to content

Commit

Permalink
fixed aspect ratio when decoding TIFF with custom size
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Jan 29, 2024
1 parent 73d99e9 commit b547b5b
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b547b5b

Please sign in to comment.