```val getContent = registerForActivityResult(Acti...
# compose
n
Copy code
val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) {
    viewModel.imageUriState.value = it
    // Handle the returned Uri
}

if (viewModel.imageUriState.value != null) {

    Log.d(TAG, "${viewModel.imageUriState.value}")
}
getContent.launch("image/*")
Hi, I got the Uri of the photo from the user's album using registerForActivityResult, how can I convert the Uri to ImageBitmap and store it in my room? i've searched a lot from StackOverflow, but there doesn't seem to be a very standard answer
If you just want to display photos it's easy enough to use Glide in accompanist, but I want to save them to a database so I can use them permanently
s
Is there a reason do you need to store image data in Room? You could store the file locally in file system and save the paths in room?
this link suggests leveraging the blob data type in room: https://stackoverflow.com/a/46356934/14840704
n
Oh yes, I forgot, but how do I store the local path?
ok i check it thank you!
a
don't want to be a bad guy here... but there're #android and #room channels on here, #compose is not the best way to ask
i
GetContent
only gives you temporary access to the Uri and its contents. You'll need to create your own copy (say, in
getFilesDir()
) and persist the relative path of that file
👍 2
n
@Ian Lake Hi
I seem to have saved the absolute path to the image using this method, how should I next use jetpack compose's Image to display the image with this path?
i
Note that there's a helpful
copyTo
method in the Kotlin Standard library which makes it easy to connect the InputStream to an OutputStream: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-input-stream/copy-to.html
You'd want to use Accompanist's Image loading libraries: https://github.com/google/accompanist#%EF%B8%8F-image-loading
n
ahh yes GlideImage?
thank you!