0
votes

It is clear that in Android Compose if the state of variable/input of a composable changes, the composable gets recomposed.

Using:

val object = remember{ mutableStateOf(Object) } 

is possible to preserve(remember) the instance of the object on each recomposition unless the mutable state gets reassigned to a different object wich will actually trigger the recomposition of the composables that use that object as argument.

Now let's assume:

val bitmap = remember { ImageBitmap() }
val canvas = remember { Canvas(bitmap) }
---
//composable
Image(bitmap, contentDescription = "..")

in this case the image gets loaded only once, even after the bitmap gets edited the Image composable will never recompose and the result never displayed on the screen.

Somebody would say to use a MutableState variable:

 val bitmap = remember { mutableStateOf(ImageBitmap()) }

but the mutable state doesnt emit if the reference of the object bitmap is the same.

What would be the best way to control the frame rate at wich the bitmap is displayed in the composable without recreating a different bitmap each time?

How are you updating the bitmap? If not bitmap, there must be something that is changing. You can use that as state.Arpit Shukla