Is there a way to extract a Canvas or Bitmap from a View?
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)
{
开发者_JAVA技巧 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?
If you are just trying to get the view as a bitmap, you can get it from the drawing cache. This should work.
view.buildDrawingCache;
Bitmap bm = view.getDrawingCache
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.
精彩评论