在画布上绘制的图像画布、图像

2023-09-12 22:38:03 作者:你别皱眉你要的我拼命给

我做了教程,画布上的教程机器人现场抽奖的Andr​​oid系统。我想知道我怎样才能和图像到画布上,所以我可以在图像上画?就像从我绘制PNG文件的主面,所以我可以借鉴的图片。 这是Android 谢谢

I did the tutorial Drawing with Canvas in Android on tutorial for androids site . I was wondering how I can get and image to the canvas so I can draw on that image? like a png file from my drawable to the main surface so I can draw on that picture. This is for android Thank You

推荐答案

画在画布上绘制对象的好办法是不是自己进行解码,但它留给系统这样做的:

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);
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.