Get Bitmap from ImageView in Android L

Utkarsh Srivastav picture Utkarsh Srivastav · Nov 11, 2014 · Viewed 87.3k times · Source

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");

Answer

Pankaj Arora picture Pankaj Arora · Nov 20, 2014

Try this:

imageView.invalidate();
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();