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");
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.
Try this:
imageView.invalidate(); BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); Bitmap bitmap = drawable.getBitmap();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With