Canvas 在 ImageView 中

Canvas in ImageView

我动态创建了 ScrollViewTableLayout

如何在 ImageView 中添加图形 (Canvas)?

Canvas canvas = new Canvas();
...
canvas.DrawPath(path, paint);


ImageView imageView = new ImageView(this);
Bitmap bitmap = Bitmap.CreateBitmap(2000, 2000, Bitmap.Config.Argb8888);
canvas.DrawBitmap(bitmap, 200, 200, paint);
button.Text = bitmap.Width + ";" + bitmap.Height;
imageView.SetImageBitmap(bitmap);
tableLayout.AddView(imageView);

如果您希望 canvas 绘制的内容显示在 ImageView 中,您需要使用位图创建 canvas,然后执行您的绘制逻辑。

这是一个基于您的代码的示例:

// 2000x2000 is VERY large for an Android bitmap - consider using a smaller size?
// You may see out of memory errors with this size.
Bitmap bitmap = Bitmap.CreateBitmap(2000, 2000, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPath(path, paint);
imageView.setImageBitmap(bitmap);