I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting Ou
I don't really recommend editing manifest like this
android:hardwareAccelerated="false" , android:largeHeap="true"
These options cause not smooth animation effect on your app. Moreover 'liveData' or changing your local DB(Sqlite, Room) activate slowly. It is bad for user experience.
So I recommend RESIZE bitmap
Below is the sample code
fun resizeBitmap(source: Bitmap): Bitmap {
val maxResolution = 1000 //edit 'maxResolution' to fit your need
val width = source.width
val height = source.height
var newWidth = width
var newHeight = height
val rate: Float
if (width > height) {
if (maxResolution < width) {
rate = maxResolution / width.toFloat()
newHeight = (height * rate).toInt()
newWidth = maxResolution
}
} else {
if (maxResolution < height) {
rate = maxResolution / height.toFloat()
newWidth = (width * rate).toInt()
newHeight = maxResolution
}
}
return Bitmap.createScaledBitmap(source, newWidth, newHeight, true)
}