I need to pick an image from the gallery of the phone in order to do some stuff with that. For this purpose I tried to follow what is inside this android pick images from gallery thread but I think it's too old, probably I need to use the intent anyway but I don't understand how and how to pass the image picked to a bitmap variable. Precisely I need to take an image and then convert it to bitmap and do other stuff (ml algorithms). Thanks.
Asked
Active
Viewed 44 times
1
-
Use [this answer from your linked-to question](https://stackoverflow.com/a/5309217/115145). In `onActivityResult()`, if you got an image (`RESULT_OK`), pass it to your favorite image-loading library (e.g., Glide, Picasso) to have it load the image on a background thread and give you a `Bitmap` to use. – CommonsWare May 10 '20 at 20:25
-
Thank you, later on I will try and let you know the results! – Simo May 10 '20 at 20:28
-
Hi, sorry to bother you again, I'm looking at this https://bumptech.github.io/glide/doc/getting-started.html#background-threads but I cannot understand how to convert the selected image into a bitmap, have you any suggestion? – Simo May 11 '20 at 15:10
-
https://bumptech.github.io/glide/doc/targets.html https://bumptech.github.io/glide/javadocs/400/com/bumptech/glide/request/target/SimpleTarget.html – CommonsWare May 11 '20 at 15:12
-
But when I take the picture then I should do all the stuffs in onActivityResult() or come back to the MainActivity? – Simo May 11 '20 at 15:51
-
My typical approach would be "none of the above": have a singleton repository object handle the network I/O and get you your bitmap. I suspect your app's architecture is not using repositories and things like that, so I cannot really answer your question. – CommonsWare May 11 '20 at 16:13
-
No, infact, because it just need to select an image from the gallery and make some inferences with ml algorithms. I just need that for personal purpose, it surely won't go to the store. – Simo May 11 '20 at 19:32