set bitmap to background of ImageView with imageView.setImageBitmap method

前端 未结 6 963
野趣味
野趣味 2021-01-31 15:16

I have an ImageView. I am using imageView.setImageBitmap to set my image as background to ImageView. But it sets my image to ImageVi

相关标签:
6条回答
  • 2021-01-31 15:58

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

    0 讨论(0)
  • 2021-01-31 16:01

    I prefer to use this because is not deprecated and it works in the lowers versions of android.

    ImageView imageView;
    Bitmap bitmap;
    Drawable drawable = new BitmapDrawable(getResources(),bitmap);
    imageView.setImageDrawable(drawable);
    
    0 讨论(0)
  • 2021-01-31 16:05

    try this..

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

    Drawable d = new BitmapDrawable(getResources(),bitmap);
    
    imageview.setBackgroundDrawable(d);
    
    0 讨论(0)
  • 2021-01-31 16:11

    Try following code to set your own bitmap as background.

    Bitmap bitmap = ...;
    ImageView imageView = ...;
    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
    imageView.setBackground(drawable);
    
    0 讨论(0)
  • 2021-01-31 16:12

    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.

    0 讨论(0)
  • 2021-01-31 16:21

    call setBackgroundDrawable withe BitmapDrawable param

    0 讨论(0)
提交回复
热议问题