画布上的可绘制图像 [英] Drawable image on a canvas

查看:29
本文介绍了画布上的可绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图像放到画布上以便在该图像上绘图?

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

推荐答案

在画布上绘制 Drawable 的好方法不是自己解码,而是让系统去做:

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

这将适用于所有类型的可绘制对象,而不仅仅是位图.并且这也意味着你可以再次使用同一个 drawable,如果只是尺寸改变了.

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.

这篇关于画布上的可绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆