fixed aspect ratio when decoding TIFF with custom size
This commit is contained in:
parent
73d99e9687
commit
b547b5b9b1
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue