Kotlin: How to convert image uri to bitmap

Edita Komarova

Most of the answers are in Java I manage to find this solution in Kotlin but it didn't work for me. I also tried finding documentation but I couldn't find one What I'm trying to do is to select photo from gallery and then I want to convert Uri to Bitmap and then save it to the Room Database.

I would like to have a code similar to that but in Kotlin

Uri imageUri = intent.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
Imageview my_img_view = (Imageview ) findViewById (R.id.my_img_view);
my_img_view.setImageBitmap(bitmap
Hascher

Use this:

val imageUri: Uri = intent.data;
val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(c.getContentResolver(), Uri.parse(imageUri))
val my_img_view = findViewById(R.id.my_img_view) as Imageview 
my_img_view.setImageBitmap(bitmap)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Kotlin: How to convert an image Uri to Bitmap to Base64

How To Convert A Bitmap Image To Uri

How to convert URI to bitmap?

How to convert an image to bitmap

How to add a URI path to a bitmap image?

Cannot Convert Bitmap to Uri

Convert from bitmap to uri

How to convert the bitmap image to mat image

how to convert BitmapDrawable or Bitmap to ImageBitmap in kotlin

Convert data from image picker intent into bitmap (Kotlin)?

How to load an image from drawable and convert to a bitmap

How to convert poor quality bitmap image to vector?

How to convert a bitmap or byte array to an image?

How to convert Byte array into bitmap image?

How to convert URI of image to image file in python

Saving bitmap as a image in Kotlin

How to load an image into imageView using a Uri and Bitmap Factory

Image does not convert to Bitmap

How to convert the Bitmap image to .pcx format for printing image in Zebra Printer

How to convert an image uri to cv::Mat

How to convert a MultiPartFile (image) to a data URI?

Convert String to Uri in Kotlin

How to convert a Base64 string into a Bitmap image to show it in a ImageView?

How to convert Bitmap image to Base64PNG string in monodroid

How to convert YUV_420_888 image to bitmap

MLKit Firebase android - How to convert FirebaseVisionFace to Image Object (like Bitmap)?

How to convert image to Bitmap after it's been cropped?

How to convert Bitmap image to byte array in wp7?

how to pass an image Uri or alternatively a bitmap to int parameter of SQLite database to save an image?