Android - ImageView: setImageBitmap VS setImageDrawable

前端 未结 5 616
灰色年华
灰色年华 2020-12-02 20:29

What is the difference between setImageBitmap and setImageDrawable?

I have an image which I would like to set dynamically from file. The tu

5条回答
  •  不思量自难忘°
    2020-12-02 20:52

    Both methods are valid and achieve the same result. In the first method you wrap your bitmap around a drawable object which is an abstraction for anything that can be drawn in a View.

    The special thing about Drawables is that they let you do all kinds of operations on the graphical object they wrap around (scaling, translation, opacity etc..).

    A bitmap is one kind of drawable, you can learn further about drawables here: http://developer.android.com/guide/topics/resources/drawable-resource.html

    In the second method, you directly access the bitmap bits without any drawable related operations and simply draw the bitmap as-is on your view.

    Hope this helps, cheers, Max.

提交回复
热议问题