Created
February 5, 2020 08:45
-
-
Save tomoima525/150b5accca4d6fb42b5a554e68c7c8d2 to your computer and use it in GitHub Desktop.
resize bitmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun getResizedBitmap(bm: Bitmap, newWidth: Int, newHeight: Int): Bitmap { | |
return withContext(Dispatchers.IO) { | |
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) | |
val resizedBitmap = Bitmap.createBitmap( | |
bm, 0, 0, width, height, matrix, false) | |
bm.recycle() | |
resizedBitmap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment