The method by @TharakaNirmana works fine, maxSize is in Kylobytes
Example:
fun getResizedBitmap(image: Bitmap, maxSize: Int): Bitmap? {
var width = image.width
var height = image.height
val bitmapRatio = width.toFloat() / height.toFloat()
if (bitmapRatio > 1) {
width = maxSize
height = (width / bitmapRatio).toInt()
} else {
height = maxSize
width = (height * bitmapRatio).toInt()
}
return Bitmap.createScaledBitmap(image, width, height, true)
}
Usage:
bitmap.let {
val data = it.value
if (data != null) {
var image = viewModel.getResizedBitmap(data, 170)
Log.d ("bitmap size", image!!.byteCount.toString()) ...
Answer
2021-12-18 12:38:11.218 25502-25502/com.jdsalasc.sophosSolutions D/bitmap size: 67200
2021-12-18 12:39:11.673 25745-25745/com.jdsalasc.sophosSolutions D/bitmap size: 67200
2021-12-18 12:39:14.511 25745-25745/com.jdsalasc.sophosSolutions D/bitmap size: 90000
2021-12-18 12:39:20.423 25745-25745/com.jdsalasc.sophosSolutions D/bitmap size: 67200
2021-12-18 12:39:40.112 25907-25907/com.jdsalasc.sophosSolutions D/bitmap size: 120000
2021-12-18 12:39:43.322 25907-25907/com.jdsalasc.sophosSolutions D/bitmap size: 120000
2021-12-18 12:39:47.314 25907-25907/com.jdsalasc.sophosSolutions D/bitmap size: 160000
2021-12-18 12:40:17.231 26069-26069/com.jdsalasc.sophosSolutions D/bitmap size: 115600
2021-12-18 12:40:19.583 26069-26069/com.jdsalasc.sophosSolutions D/bitmap size: 86360
how you see, the bytes size never comes over 150 kb
Thank you Zoe and TharakaNirmana c: