Compartilhar via


Como: Processar gráficos armazenados em buffer manualmente

Se você estiver gerenciando seus próprios elementos gráficos em buffer, você precisará ser capaz de criar e processar os buffers de elementos gráficos.Você pode criar instâncias do BufferedGraphics classe que está associado ao desenho superfícies em sua tela, chamando o Allocate. Esse método cria um BufferedGraphics instância que está associada a uma superfície de renderização específico, sistema autônomo um formulário ou controle. Depois que você criou um BufferedGraphics instância, você pode desenhar elementos gráficos para o buffer que ele representa através de Graphics propriedade. Após ter executado todas as operações de elementos gráficos, você pode copiar o Sumário do buffer na tela chamando o Render método.

Observação:

Se você executar seu próprio renderização, consumo de memória aumentará, embora o aumento só possa ser pequeno.

Para exibir manualmente em buffer elementos gráficos

  1. Obter uma referência a uma instância do BufferedGraphicsContext classe. Para obter mais informações, consulte Como: Gerenciar manualmente Graphics no buffer.

  2. Criar uma instância do BufferedGraphics classe chamando o Allocate método, sistema autônomo neste exemplo de código a seguir.

    ' 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. Desenhar gráfico para o buffer de elementos gráficos, definindo o Graphics propriedade. Por exemplo:

    ' 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. Quando tiver concluído todas sistema autônomo operações de desenho para o buffer de elementos gráficos, telefonar o Render método para processar o buffer, seja para a superfície de desenho associados a esse buffer ou para uma superfície de desenho especificada, sistema autônomo neste exemplo de código a seguir.

    ' 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. Após terminar de renderização de gráficos, chame o Dispose método na BufferedGraphics instância para liberar recursos do sistema.

    myBuffer.Dispose()
    
    myBuffer.Dispose();
    

Consulte também

Tarefas

Como: Gerenciar manualmente Graphics no buffer

Conceitos

Duplo em buffer Graphics

Referência

BufferedGraphicsContext

BufferedGraphics