0

The Code A comes from the project. The author get the file path with val resourcesPrefix = "src/nativeMain/resources" and FileSource(path = "$resourcesPrefix/image.png".toPath() ..., you can see the file structure with Image A.

The Image B is the file structure of my project, how can I get the file path? so I can pass the path parameter to the function ImageEdit(...) .

BTW, I don't know whether the Code C is correct.

Code A

val resourcesPrefix = "src/nativeMain/resources"

println("\n> Edit images...")
val imageEdit = ImageEdit(
    image = FileSource(path = "$resourcesPrefix/image.png".toPath(), fileSystem = FileSystem.SYSTEM),
    mask = FileSource(path = "$resourcesPrefix/mask.png".toPath(), fileSystem = FileSystem.SYSTEM),
    prompt = "a sunlit indoor lounge area with a pool containing a flamingo",
    n = 1,
    size = ImageSize.is1024x1024,
)

Image A enter image description here

Code B

val resourcesPrefix = "?????"
val imageEdit = ImageEdit(
      image = FileSource(path = "$resourcesPrefix/image.png".toPath(), fileSystem = FileSystem.SYSTEM),
        mask = FileSource(path = "$resourcesPrefix/mask.png".toPath(), fileSystem = FileSystem.SYSTEM),
        prompt = "a sunlit indoor lounge area with a pool containing a flamingo",
        n = 1,
        size = ImageSize.is256x256,
)     

Image B enter image description here

Code C

        val file1="drawable://" + R.drawable.image
        val file2="drawable://" + R.drawable.mask
        val imageEdit = ImageEdit(
            image = FileSource(path = file1.toPath(), fileSystem = FileSystem.SYSTEM),
            mask = FileSource(path = file1.toPath(), fileSystem = FileSystem.SYSTEM),
            prompt = "a sunlit indoor lounge area with a pool containing a flamingo",
            n = 1,
            size = ImageSize.is256x256,
        )
HelloCW
  • 843
  • 22
  • 125
  • 310
  • Does this answer your question? [Get path of Android resource](https://stackoverflow.com/questions/6301493/get-path-of-android-resource) – dominicoder Apr 15 '23 at 02:33
  • 1
    There is no file path, as those are files on your development machine, not on the Android device. – CommonsWare Apr 15 '23 at 11:18

1 Answers1

0

To get a Source for drawable, sound, and raw resources, you can use this function:

fun Context.getResourceSource(resource: Int): Source {
    return resources.openRawResource(resource).source()
}

Use the function to create a FileSource:

val source = getResourceSource(R.drawable.mask)
val fileSource = FileSource("mask.png", source)
Aallam
  • 21
  • 6