Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/extension/BitmapFactoryExtensions.kt

14 lines
492 B
Kotlin

package org.mariotaku.twidere.extension
import android.graphics.BitmapFactory
fun BitmapFactory.Options.calculateInSampleSize(preferredWidth: Int, preferredHeight: Int): Int {
if (preferredHeight > outHeight && preferredWidth > outWidth) {
return 1
}
if (preferredHeight <= 0 && preferredWidth <= 0) {
return 1
}
val result = Math.round(Math.max(outWidth, outHeight) / Math.max(preferredWidth, preferredHeight).toFloat())
return Math.max(1, result)
}