다음을 통해 공유


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

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

참고

사용자 고유 렌더링을 수행하는 경우 증가량은 적지만 메모리 사용량이 증가합니다.

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

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

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

            ' 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)
    
    
    // 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);
    
  3. Graphics 속성을 설정하여 그래픽 버퍼에 그래픽을 그립니다. 예를 들면 다음과 같습니다.

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

    ' 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)
    
    // 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());
    
  5. 그래픽 렌더링이 끝난 후에는 BufferedGraphics 인스턴스에서 Dispose 메서드를 호출하여 시스템 리소스를 해제합니다.

    myBuffer.Dispose()
    
    myBuffer.Dispose();
    

참고 항목

작업

방법: 버퍼링된 그래픽 수동 관리

참조

BufferedGraphicsContext

BufferedGraphics

개념

이중 버퍼링 그래픽