Compartir a través de


Cómo: Representar manualmente gráficos almacenados en búfer

Actualización: noviembre 2007

Si está administrando sus propios gráficos almacenados en búfer, deberá ser capaz de crear y representar búferes de gráficos. Puede crear instancias de la clase BufferedGraphics asociada a las superficies de dibujo en la pantalla llamando a Allocate. Este método crea una instancia de BufferedGraphics que se asocia a una superficie de representación determinada, como un formulario o un control. Después de crear una instancia de BufferedGraphics, se pueden dibujar gráficos en el búfer que representa mediante la propiedad Graphics. Después de realizar todas las operaciones de gráficos, se puede copiar el contenido del búfer en la pantalla mediante una llamada al método Render.

Nota:

Si realiza su propia representación, aumentará el consumo de memoria, aunque este aumento puede ser leve.

Para mostrar manualmente los gráficos almacenados en búfer

  1. Obtenga una referencia a una instancia de la clase BufferedGraphicsContext. Para obtener más información, vea Cómo: Administrar manualmente gráficos almacenados en búfer.

  2. Cree una instancia de la clase BufferedGraphics llamando al método Allocate, como se muestra en el ejemplo de código siguiente.

    ' 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. Dibuje los gráficos en el búfer de gráficos estableciendo la propiedad Graphics. Por ejemplo:

    ' 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. Cuando se hayan completado todas las operaciones de dibujo en el búfer de gráficos, llame al método Render para representar el búfer, ya sea en la superficie de dibujo asociada a dicho búfer o en una superficie de dibujo especificada, tal como se muestra en el ejemplo de código siguiente.

    ' 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. Después de finalizar la representación de gráficos, llame al método Dispose en la instancia BufferedGraphics para liberar recursos del sistema.

    myBuffer.Dispose()
    
    myBuffer.Dispose();
    

Vea también

Tareas

Cómo: Administrar manualmente gráficos almacenados en búfer

Conceptos

Gráficos de doble búfer

Referencia

BufferedGraphicsContext

BufferedGraphics