Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bitmap from imageView

I need to take an image from imageView and make it as a bitmap.

String s = getIntent().getStringExtra("ImageUri");
mImageViewFilter = (ImageView) findViewById(R.id.imageViewFilter);
Glide.with(this)
          .load(s)
          .into(mImageViewFilter);
Bitmap bitmap = ((BitmapDrawable)mImageViewFilter.getDrawable()).getBitmap();

You can see that into mImageViewFilter I am loading a photo with use of its URI and Glide library. My next step is to take this photo which is in mImageViewFilter and make it as a bitmap. After the last line of code there is an exception. What am I doing wrong?

like image 969
Stegenda Avatar asked Dec 02 '25 09:12

Stegenda


1 Answers

String s = getIntent().getStringExtra("ImageUri");
mImageViewFilter = (ImageView) findViewById(R.id.imageViewFilter);

To load image into ImageView use below code

Glide.with(this).load(s).into(mImageViewFilter);

So in order to get bitmap from ImageView (mImageViewFilter )

Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();

OR

You can add this before the code where you are trying to get Bitmap out of the ImageView

mImageViewFilter.setDrawingCacheEnabled(true);

In order to get the Bitmap out of the ImageView using DrawingCache, you first need to enable ImageView to draw image cache.

Bitmap bitmap = mImageViewFilter.getDrawingCache();
like image 199
Manish Singh Rana Avatar answered Dec 08 '25 15:12

Manish Singh Rana