3

I saw this answer: What is the difference between Bitmap and Drawable in Android?

Can anyone give a practical explanation? When to use? Advantage disadvantage?

Community
  • 1
  • 1
Kim Montano
  • 2,185
  • 4
  • 26
  • 39
  • 3
    Think of it this way: JPEG and PNG are two examples of image encodings. So when you are dealing with images there are two things you want to do: decode an image (turn the stream into pixels) and render the image. `Bitmap` is all about encoding/decoding/manipulating the pixels. `Drawable` is all about rendering things onto the screen so you can see them. `BitmapDrawable` is where it all comes together. – kris larson Nov 26 '15 at 02:16

1 Answers1

4

Bitmap is just an image as-is. Ideally it would be used to draw pixels on the screen with a Canvas, using a SurfaceView or something like that.

Drawable is a class that describes something that can be drawn on the screen.

BitmapDrawable is a subclass from Drawable. This means that it's a Drawable that wants to draw an image.

Usually android views work with Drawable objects, so any subclass of Drawable is acceptable, this means that if you want to use a Bitmap (raw pixels) on a View you need to create a BitmapDrawable and pass it to it.

TomTsagk
  • 1,474
  • 9
  • 23