DrawingVisual 构造函数

定义

初始化 DrawingVisual 类的新实例。

public:
 DrawingVisual();
public DrawingVisual ();
Public Sub New ()

示例

在下面的示例中,创建了 一个 DrawingVisual 对象,并绘制了一个矩形到其绘图上下文中。 请注意,必须调用 CloseDrawingContext 方法来保存绘图内容。

// Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext in order to create new drawing content.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Create a rectangle and draw it in the DrawingContext.
    Rect rect = new Rect(new System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
    drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);

    // Persist the drawing content.
    drawingContext.Close();

    return drawingVisual;
}
' Create a DrawingVisual that contains a rectangle.
Private Function CreateDrawingVisualRectangle() As DrawingVisual
    Dim drawingVisual As New DrawingVisual()

    ' Retrieve the DrawingContext in order to create new drawing content.
    Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

    ' Create a rectangle and draw it in the DrawingContext.
    Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
    drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

    ' Persist the drawing content.
    drawingContext.Close()

    Return drawingVisual
End Function

注解

创建 DrawingVisual 对象时,该对象没有绘图内容。 可以通过检索对象的绘图上下文并绘制到对象中来添加文本、图形或图像内容。 通过调用 RenderOpen 对象的 DrawingVisual 方法来返回绘图上下文。

适用于