dzaitsev
10/21/2023, 10:41 AMImageBitmap to draw a png image on the canvas, and I can't find a method in mpp to create an object of this type from a resource.
Any advice and help would be appreciated.Michael Paus
10/21/2023, 1:35 PMdzaitsev
10/23/2023, 6:49 AMMichael Paus
10/23/2023, 9:56 AMpainter = painterResource("sample.png")
The above code gives you a painter and you can directly draw that into a DrawScope without having to use any platform dependent API.dzaitsev
10/23/2023, 10:30 AMDrawScope allows to draw `ImageBitmap`s not `Painter`s returned from painterResource.
I can't just create an instance of Painter and draw it on Canvas. The canvas API requires ImageBitmap. And I can't find a method in mp that can create that ImageBitmap from the file path like imageBitmap("sample.png) or so.dzaitsev
10/23/2023, 10:54 AMresource("image.png).rememberImageBitmap().orEmpty()Michael Paus
10/23/2023, 12:48 PMimport androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
@Composable
fun TestPainterOnCanvas(modifier: Modifier = Modifier) {
val painter = painterResource("image.png")
Canvas(modifier) {
with(painter) { draw(intrinsicSize) }
}
}dzaitsev
10/23/2023, 1:06 PM