Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

java - 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");
question from:https://stackoverflow.com/questions/26865787/get-bitmap-from-imageview-in-android-l

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...