Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve bitmap from uri

I have included 'share via myApp' option. I inserted following code in the receiving activity class.

    // Get the intent that started this activity
    Intent intent = getIntent();
    Uri data = intent.getData();

    // Figure out what to do based on the intent type
    if (intent.getType().indexOf("image/") != -1) {
        // Handle intents with image data ...
}

What is the next step to retrieve bitmap image.

like image 390
Robert Avatar asked Dec 26 '13 09:12

Robert


People also ask

How do I find the URI of a picture?

Ideally, your "upload to a server" logic can work with an InputStream . In that case, call openInputStream() on a ContentResolver to get an InputStream on the content identified by the Uri .

How do I get bitmap from imageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)


4 Answers

As you have already get the Uri. Now you have to pass that Uri in getBitmap() to get bitmap and use that bitmap.

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);
like image 136
Chintan Khetiya Avatar answered Oct 10 '22 04:10

Chintan Khetiya


For getting bitmap from uri,

Bitmap  mBitmap = Media.getBitmap(this.getContentResolver(), uri);

Hope this helps you.

like image 34
nikvs Avatar answered Oct 10 '22 05:10

nikvs


This is work for me

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
    Uri imageUri = data.getData();
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
}
}
like image 1
Faxriddin Abdullayev Avatar answered Oct 10 '22 06:10

Faxriddin Abdullayev


Retrive bitmap from uri.....

public static Bitmap decodeUriToBitmap(Context mContext, Uri sendUri) {
        Bitmap getBitmap = null;
        try {
            InputStream image_stream;
            try {
                image_stream = mContext.getContentResolver().openInputStream(sendUri);
                getBitmap = BitmapFactory.decodeStream(image_stream);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getBitmap;
    }
like image 3
Praful Parmar Avatar answered Oct 10 '22 05:10

Praful Parmar