set bitmap to background of ImageView with imageView.setImageBitmap method

user2567369 picture user2567369 · Sep 18, 2013 · Viewed 87.5k times · Source

I have an ImageView. I am using imageView.setImageBitmap to set my image as background to ImageView. But it sets my image to ImageView's source (i.e. android:src) , but it doesn't set my image to ImageView's background (i.e. android:background).

When I use imageView.setImageBitmap, it looks like as if I used imageView.setImageResource not imageView.setBackgroundResource.

How can I handle this if I want to set my image to background using imageView.setImageBitmap. I know by I can do this by making custom ImageView. But is it possible without custom ImageView? If its possible, please let me know how to do it.

Answer

Panchal Amit picture Panchal Amit · Sep 18, 2013

I have tested and it's done

I think you are getting Bitmap

So you have to convert Bitmap to BitmapDrawable

like

  BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap)

then just set bitmap with below function

  imageView.setBackground(ob);

by this way you can do it..