kotlin : bitmap 크기 조절하기

2023. 8. 25. 00:55[Android APP] feat. Kotlin/Kotlin 공부

fun getResizedBitmap(bm: Bitmap, newHeight: Int, newWidth: Int): Bitmap {
    val width = bm.width
    val height = bm.height
    val scaleWidth = newWidth.toFloat() / width
    val scaleHeight = newHeight.toFloat() / height
    val matrix = Matrix()
    matrix.postScale(scaleWidth, scaleHeight)
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false)
}
handler.postDelayed({
    imageView.setImageBitmap(getResizedBitmap(bitmap, 1000, 1000))
}, 0)

 

반응형