방법: 버퍼링된 그래픽 수동 렌더링

버퍼링된 고유한 그래픽을 관리하는 경우 그래픽 버퍼를 만들고 렌더링할 수 있어야 합니다. Allocate 메서드를 호출하여 화면의 그리기 화면과 연결된 BufferedGraphics 클래스의 인스턴스를 만들 수 있습니다. 이 메서드는 폼 또는 컨트롤과 같은 특정 렌더링 화면과 연결된 BufferedGraphics 인스턴스를 만듭니다. BufferedGraphics 인스턴스를 만든 후 Graphics 속성을 통해 나타내는 버퍼에 통해 나타내는 버퍼에 그래픽을 그릴 수 있습니다. 모든 그래픽 작업을 수행한 후 Render 메서드를 호출하여 버퍼 내용을 화면에 복사할 수 있습니다.

참고

고유한 렌더링을 수행하는 경우 약간의 증가이긴 하지만 메모리 사용이 증가합니다.

버퍼링된 그래픽을 수동으로 표시하려면

  1. BufferedGraphicsContext 클래스의 인스턴스에 대한 참조를 가져옵니다. 자세한 내용은 방법: 버퍼링된 그래픽 수동 관리를 참조하세요.

  2. 다음 코드 예제와 같이 Allocate 메서드를 호출하여 BufferedGraphics 클래스의 인스턴스를 만듭니다.

    // This example assumes the existence of a form called Form1.
    BufferedGraphicsContext currentContext;
    BufferedGraphics myBuffer;
    // Gets a reference to the current BufferedGraphicsContext
    currentContext = BufferedGraphicsManager.Current;
    // Creates a BufferedGraphics instance associated with Form1, and with
    // dimensions the same size as the drawing surface of Form1.
    myBuffer = currentContext.Allocate(this.CreateGraphics(),
       this.DisplayRectangle);
    
    ' This example assumes the existence of a form called Form1.
    Dim currentContext As BufferedGraphicsContext
    Dim myBuffer As BufferedGraphics
    ' Gets a reference to the current BufferedGraphicsContext.
    currentContext = BufferedGraphicsManager.Current
    ' Creates a BufferedGraphics instance associated with Form1, and with 
    ' dimensions the same size as the drawing surface of Form1.
    myBuffer = currentContext.Allocate(Me.CreateGraphics, _
       Me.DisplayRectangle)
    
    
  3. Graphics 속성을 설정하여 그래픽 버퍼에 그래픽을 그립니다. 예를 들면 다음과 같습니다.

    // Draws an ellipse to the graphics buffer.
    myBuffer.Graphics.DrawEllipse(Pens.Blue, this.DisplayRectangle);
    
    ' Draws an ellipse to the graphics buffer.
    myBuffer.Graphics.DrawEllipse(Pens.Blue, Me.DisplayRectangle)
    
  4. 그래픽 버퍼에 그리기 작업을 모두 완료했으면, 다음 코드 예제와 같이 Render 메서드를 호출하여 해당 버퍼와 연결된 그리기 화면이나 지정된 그리기 화면에 버퍼를 렌더링합니다.

    // This example assumes the existence of a BufferedGraphics instance
    // called myBuffer.
    // Renders the contents of the buffer to the drawing surface associated
    // with the buffer.
    myBuffer.Render();
    // Renders the contents of the buffer to the specified drawing surface.
    myBuffer.Render(this.CreateGraphics());
    
    ' Renders the contents of the buffer to the drawing surface associated 
    ' with the buffer.
    myBuffer.Render()
    ' Renders the contents of the buffer to the specified drawing surface.
    myBuffer.Render(Me.CreateGraphics)
    
  5. 그래픽 렌더링을 마친 후 BufferedGraphics 인스턴스에 대해 Dispose 메서드를 호출하여 시스템 리소스를 해제합니다.

    myBuffer.Dispose();
    
    myBuffer.Dispose()
    

참고 항목