Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set bitmap to background of ImageView with imageView.setImageBitmap method

People also ask

How do I turn an ImageView into a bitmap?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap();


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..


Try following code to set your own bitmap as background.

Bitmap bitmap = ...;
ImageView imageView = ...;
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setBackground(drawable);

try this..

Create drawable using bitmap & use setBackgroundDrawable(Drawable d) method for imageview.

Drawable d = new BitmapDrawable(getResources(),bitmap);

imageview.setBackgroundDrawable(d);

Please Use the following line to set image background.

imageview.setBackground(getResources().getDrawable(R.drawable.uporder));

Here uporder is an image resource present in your drawablefolder.