Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load image in Kotlin Compose desktop?

How to load images from the hard disk when using Kotlin compose on the desktop?

like image 831
Haseeb Pavaratty Avatar asked Dec 17 '22 12:12

Haseeb Pavaratty


1 Answers

other answers are outdated, as per Compose 1.0.0-beta5 you should do the following:

Image(painterResource("image.jpg"))

if you want to load a bitmap only

val bitmap = useResource("image.jpg") { loadImageBitmap(it) }

Only the file name is required (not full path), but make sure that your resources are in src/main/resources/image.jpg

like image 175
sonique Avatar answered Jan 02 '23 01:01

sonique