Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Jeśli zarządzasz własnymi buforami graficznymi, musisz mieć możliwość ich tworzenia i renderowania. Możesz utworzyć wystąpienia klasy BufferedGraphics skojarzonej z powierzchniami rysunkowymi na ekranie, wywołując metodę Allocate. Ta metoda tworzy wystąpienie BufferedGraphics skojarzone z określoną powierzchnią renderowania, taką jak formularz lub kontrolka. Po utworzeniu wystąpienia BufferedGraphics można narysować grafikę w buforze reprezentowanym przez właściwość Graphics. Po wykonaniu wszystkich operacji graficznych można skopiować zawartość buforu na ekran, wywołując metodę Render.
Nota
Jeśli wykonasz własne renderowanie, zużycie pamięci wzrośnie, chociaż wzrost może być niewielki.
Aby ręcznie wyświetlić buforowaną grafikę
Uzyskaj odwołanie do wystąpienia klasy BufferedGraphicsContext. Aby uzyskać więcej informacji, zobacz Instrukcje: Ręczne zarządzanie buforowaną grafiką.
Utwórz wystąpienie klasy BufferedGraphics, wywołując metodę Allocate, jak pokazano w poniższym przykładzie kodu.
// 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)
Rysuj grafikę do buforu graficznego, ustawiając właściwość Graphics. Na przykład:
// 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)
Po zakończeniu wszystkich operacji rysowania do buforu grafiki wywołaj metodę Render w celu renderowania buforu na powierzchni rysunku skojarzonej z tym buforem lub do określonej powierzchni rysunku, jak pokazano w poniższym przykładzie kodu.
// 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)
Po zakończeniu renderowania grafiki wywołaj metodę
Dispose
w wystąpieniu BufferedGraphics, aby zwolnić zasoby systemowe.myBuffer.Dispose();
myBuffer.Dispose()
Zobacz też
.NET Desktop feedback