how do i access an image file located in my resour...
# compose-desktop
t
how do i access an image file located in my resources directory from kotlin (non composable scope) code?
for context im trying to draw an image into
java. awt. Graphics2D
along with some other stuff. i can do it fine if i use
File(absolute path)
but i don't want to hard code the path to the image form my machine
t
Not sure if this helps for you specific problem but for compose multiplatform here is a documentation how to do it: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#resource-usage Maybe not exactly what you are searching for but maybe if you do not want to have mutliplatform this also works for CfD only.
thank you color 1
t
Thanks so much!! i looked at both links and it seems that i was using
java.classLoader.gerResourceAsStream
wrong i should put the file in
desktomMain/resources
not in
commonMain/composeResources
or
commonMain/resources
😂😂, also i tried the compose multiplatform api
Res.readBytes
but it did not work for my case.