Drawable image on a canvas

后端 未结 6 1167
有刺的猬
有刺的猬 2020-11-28 22:57

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

6条回答
  •  感动是毒
    2020-11-28 23:31

    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.

提交回复
热议问题