1

I have a dynamic, clickable ImageView. Basically, once the user clicks the ImageView, s/he can add an image to be displayed inside the view. I want to find a way to get the current image housed in the ImageView and turn it into a bitmap.

So far, this is my attempt:

Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), (BitmapDrawable)imageView.getDrawable());

But it is giving me a Wrong 2nd argument type error, as it is expecting an int.

I'm keeping the post brief for now for clarity. I can post more code per request.

1 Answers1

2

get Bitmap with this method :

BitmapDrawable bitmapDrawable = ((BitmapDrawable) imageView.getDrawable());
Bitmap bitmap = bitmapDrawable .getBitmap();

decodeResource gives you bitmap from resource , for example , if you want to read an image from drawable folder you need decodeResource but in this case you can get bitmap from imageview directly

Koorosh Ghorbani
  • 507
  • 4
  • 14
  • Thank you, Koorosh. I've upvoted and accepted your answer. If you think that this was a well asked question, could you kindly give me an upvote as well? – Andros Adrianopolos Feb 21 '19 at 00:35