共用方式為


HOW TO:手動呈現已緩衝的圖形

更新:2007 年 11 月

如果您是自己管理已緩衝的圖形,就必須能夠建立及呈現圖形緩衝區。您可以呼叫 Allocate,以建立與螢幕的繪圖介面相關聯之 BufferedGraphics 類別的執行個體。這個方法會建立與特定呈現介面 (例如表單或控制項) 相關聯的 BufferedGraphics 執行個體。在建立 BufferedGraphics 執行個體之後,就可以將圖形繪製到它透過 Graphics 屬性所代表的緩衝區。在執行了所有圖形作業之後,便可呼叫 Render 方法將緩衝區的內容複製到螢幕。

注意事項:

如果您是自己執行呈現作業,會增加記憶體耗用量,但增加的耗用量可能微不足道。

若要手動顯示已緩衝的圖形

  1. 取得 BufferedGraphicsContext 類別之執行個體的參考。如需詳細資訊,請參閱 HOW TO:手動管理已緩衝的圖形

  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();
    

請參閱

工作

HOW TO:手動管理已緩衝的圖形

概念

雙重緩衝的圖形

參考

BufferedGraphicsContext

BufferedGraphics