Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ImageView: setImageBitmap VS setImageDrawable

What is the difference between setImageBitmap and setImageDrawable?

I have an image which I would like to set dynamically from file. The tutorial that I followed says to convert my Bitmap to a BitmapDrawable then set it using setImageDrawable. I've notice that setting the Bitmap directly with setImageBitmap also works but I don't notice any difference.

Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); BitmapDrawable bitmapDrawable = new BitmapDrawable(image); imageView.setImageDrawable(bitmapDrawable); 

OR

Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); imageView.setImageBitmap(image); 
like image 819
meeeee Avatar asked Aug 17 '12 07:08

meeeee


1 Answers

There is no difference between the two internally setImageBitmap is calling setImageDrawable.

Below code is picked from ImageView.java of AOSP

public void setImageBitmap(Bitmap bm) {     // if this is used frequently, may handle bitmaps explicitly     // to reduce the intermediate drawable object     setImageDrawable(new BitmapDrawable(mContext.getResources(), bm)); } 
like image 126
nandeesh Avatar answered Sep 17 '22 04:09

nandeesh