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
379 views
in Technique[技术] by (71.8m points)

android - set bitmap to background of ImageView with imageView.setImageBitmap method

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.

question from:https://stackoverflow.com/questions/18870435/set-bitmap-to-background-of-imageview-with-imageview-setimagebitmap-method

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

1 Answer

0 votes
by (71.8m points)

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


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

...