Get Bitmap attached to ImageView
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();
This will get you a Bitmap
from the ImageView
. Though, it is not the same bitmap object that you've set. It is a new one.
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
=== EDIT ===
imageView.setDrawingCacheEnabled(true);
imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imageView.layout(0, 0,
imageView.getMeasuredWidth(), imageView.getMeasuredHeight());
imageView.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(imageView.getDrawingCache());
imageView.setDrawingCacheEnabled(false);
Write below code
ImageView yourImageView = (ImageView) findViewById(R.id.yourImageView);
Bitmap bitmap = ((BitmapDrawable)yourImageView.getDrawable()).getBitmap();
For those who are looking for Kotlin
solution to get Bitmap
from ImageView
.
var bitmap = (image.drawable as BitmapDrawable).bitmap