Drawable image on a canvas

Lana picture Lana · Mar 3, 2011 · Viewed 167.7k times · Source

How can I get an image to the canvas in order to draw on that image?

Answer

Gábor picture Gábor · Apr 8, 2014

The good way to draw a Drawable on a canvas is not decoding it yourself but leaving it to the system to do so:

Drawable d = getResources().getDrawable(R.drawable.foobar, null);
d.setBounds(left, top, right, bottom);
d.draw(canvas);

This will work with all kinds of drawables, not only bitmaps. And it also means that you can re-use that same drawable again if only the size changes.