如何在 android studio 中将图像视图绘制到 canvas 中?

How to draw a imageview into a canvas in android studio?

嗨,我想在 android studio

中将图像视图绘制到 canvas

我发现这段代码可以绘制可绘制对象,但我希望它绘制图像视图

        Drawable drawable = getResources().getDrawable
                (R.mipmap.ic_launcher);
        drawable.setBounds(20, 30, drawable.getIntrinsicWidth()+20, drawable.getIntrinsicHeight()+30);
        drawable.draw(canvas);

这就是我想要它画的

ImageView thisisImg= (ImageView)findViewById(R.id.ImageView01);

我该怎么做? 谢谢

只需使用 ImageView 中的 getDrawable()。 你的例子会变成:

ImageView thisisImg= (ImageView)findViewById(R.id.ImageView01);

Drawable drawable = thisisImg.getDrawable();

drawable.setBounds(20, 30, drawable.getIntrinsicWidth()+20, drawable.getIntrinsicHeight()+30);
drawable.draw(canvas);