有没有办法从视图中提取画布或位图?
我有一个扩展 View
并绘制一条线的类:
public class MyDraw extends View
{
Paint paint = new Paint();
public MyDraw(Context context)
{
super(context);
paint.setColor(Color.BLUE);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawLine(1, 1, 100, 100, paint);
}
}
我想使用 Context
中的现有视图在其之上绘制。是否可以?
I have this class that extends View
and draws a line:
public class MyDraw extends View
{
Paint paint = new Paint();
public MyDraw(Context context)
{
super(context);
paint.setColor(Color.BLUE);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawLine(1, 1, 100, 100, paint);
}
}
I would like to use the existing view from the Context
to draw on top of it. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是尝试以位图形式获取视图,则可以从绘图缓存中获取它。这应该有效。
您不能使用现有的视图实例并再次添加它,因为它已经分配了一个父视图,这将导致异常。
If you are just trying to get the view as a bitmap, you can get it from the drawing cache. This should work.
You cannot use the exisitng view instance and add it again as it already has a parent assigned to it and it wil cause an exception.