Last active
August 4, 2022 19:25
-
-
Save zekierciyas/79211b9959c8a1fc54bd3216b2e724e1 to your computer and use it in GitHub Desktop.
BitmapExtentions
This file contains 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
fun Bitmap.resizeImage(image: Bitmap, maxWidth: Int, maxHeight: Int, onComplete: (bitmap: Bitmap?) -> Unit) { | |
val width = image.width | |
val height = image.height | |
val scaleWidth = maxWidth.toFloat() / width | |
val scaleHeight = maxHeight.toFloat() / height | |
val matrix = Matrix() | |
matrix.postScale(scaleWidth, scaleHeight) | |
// Create a New bitmap | |
val resizedBitmap = Bitmap.createBitmap( | |
image, 0, 0, width, height, matrix, false) | |
onComplete(resizedBitmap) | |
resizedBitmap.recycle() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment