fun resize(x: Bitmap, max: Int): Bitmap {
    var width = x.width
    var height = x.height
    val scale: Double = width.toDouble() / height.toDouble()
    if (scale > 1) {
        width = max
        var newHeight = width / scale
        height = newHeight.toInt()
    } else {
        height = max
        var newWidth = height * scale
        width = newWidth.toInt()
    }
    return Bitmap.createScaledBitmap(x, width / 2, height / 2, true)
}
This is the code to execute it
        val smallBitmap = small(bitmap!!, 300)
        val outputStream = ByteArrayOutputStream()
        smallBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
        val byteArray = outputStream.toByteArray()
I have 2 fragments. And I am picking photo from the gallery and pass it to other fragment. And when I send it the photos come out too pixelated and blurry. It's because of resize and scaling. But I do not know what to do.
