Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Bitmap from ImageView in Android L

I want to get Bitmap from ImageView. I have used following code, but getDrawable() returns null. How to get whole Bitmap from ImageView.

Bitmap bitmap; if (mImageViewer.getDrawable() instanceof BitmapDrawable) {     bitmap = ((BitmapDrawable) mImageViewer.getDrawable()).getBitmap(); } else {     Drawable d = mImageViewer.getDrawable();     bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);     Canvas canvas = new Canvas(bitmap);     d.draw(canvas); } storeImage(bitmap,"final.jpeg"); 
like image 968
Utkarsh Srivastav Avatar asked Nov 11 '14 13:11

Utkarsh Srivastav


People also ask

What is bitmap drawable?

android.graphics.drawable.BitmapDrawable. A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object. It can be defined in an XML file with the <bitmap> element.


1 Answers

Try this:

imageView.invalidate(); BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); Bitmap bitmap = drawable.getBitmap(); 
like image 134
Pankaj Arora Avatar answered Sep 18 '22 07:09

Pankaj Arora