DrawingVisual.RenderOpen 메서드

정의

렌더링에 사용할 DrawingVisual 개체를 엽니다. 반환된 DrawingContext 값은 DrawingVisual로 렌더링하는 데 사용할 수 있습니다.

public:
 System::Windows::Media::DrawingContext ^ RenderOpen();
public System.Windows.Media.DrawingContext RenderOpen ();
member this.RenderOpen : unit -> System.Windows.Media.DrawingContext
Public Function RenderOpen () As DrawingContext

반환

DrawingContext

DrawingContext 형식의 값입니다.

예제

다음 예제에서는 DrawingVisual 개체를 만든 고 DrawingContext 반환 합니다.

// 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

그리기 컨텍스트에 그리는 순서가 중요합니다. 성공한 각 그리기는 다른 드로잉 위에 그려집니다. 다음 예제에서는 사각형의 먼저 그린된 다음 텍스트입니다.

// Retrieve the DrawingContext in order to draw into the visual object.
DrawingContext drawingContext = drawingVisual.RenderOpen();

// Draw a rectangle into the DrawingContext.
Rect rect = new Rect(new Point(160, 100), new Size(320, 80));
drawingContext.DrawRectangle(Brushes.LightBlue, (Pen)null, rect);

// Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(
   new FormattedText("Hello, world",
      CultureInfo.GetCultureInfo("en-us"),
      FlowDirection.LeftToRight,
      new Typeface("Verdana"),
      36, Brushes.Black),
      new Point(200, 116));

// Persist the drawing content.
drawingContext.Close();
' Retrieve the DrawingContext in order to draw into the visual object.
Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

' Draw a rectangle into the DrawingContext.
Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

' Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(New FormattedText("Hello, world", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 36, Brushes.Black), New Point(200, 116))

' Persist the drawing content.
drawingContext.Close()

설명

호출 하는 경우는 Close 메서드를 DrawingContext, 현재 그리기 콘텐츠 대체에 대해 정의 된 모든 이전 그리기 콘텐츠는 DrawingVisual합니다. 이 기존 그리기 콘텐츠를 새 그리기 콘텐츠를 추가할 수 없습니다 임을 의미 합니다.

적용 대상

추가 정보