Convert image to bitmap in android

I want to select a picture from the SD card of a mobile phone. I use the code below to select and display in my activity

Uri selectedImageUri = data.getData(); selectedImagePath = getPath(selectedImageUri); Uri uri = Uri.parse(selectedImagePath); uploadimage.setImageURI(uri); 

It works fine, but I want to convert this image to Bitmap , I have a path to the image and a URI.

How to convert image to bitmap in this case? Please help me, thanks in advance.

+6
source share
2 answers

use this code

 Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); 
+20
source
 Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri); ImageView imageView = (ImageView) findViewById(R.id.imageView); imageView.setImageBitmap(bitmap); 
0
source

Source: https://habr.com/ru/post/894248/


All Articles