Nasıl yapılır: Arabelleğe Alınan Grafikleri Elle İşleme
Arabelleğe alan kendi grafiklerinizi yönetiyorsanız grafik arabellekleri oluşturabilecek ve işleyabileceksiniz. yöntemini çağırarak ekran BufferedGraphics üzerinde çizim yüzeyleriyle ilişkili sınıfının örneklerini Allocate oluşturabilirsiniz. Bu yöntem, BufferedGraphics form veya denetim gibi belirli bir işleme yüzeyiyle ilişkili bir örnek oluşturur. Bir örnek oluşturduktan BufferedGraphics sonra, özelliği aracılığıyla temsil ettiği arabelleğe grafik Graphics çizin. Tüm grafik işlemlerini gerçekleştirdikten sonra yöntemini çağırarak arabelleğin içeriğini ekrana Render kopyaabilirsiniz.
Not
Kendi işlemenizi gerçekleştirecek olursanız bellek tüketimi artar, ancak bu artış yalnızca küçük olabilir.
Arabelleğe alan grafikleri el ile görüntülemek için
Sınıfının bir örneğine başvuru BufferedGraphicsContext alın. Daha fazla bilgi için bkz. Nasıl yapılır: Arabelleğe Alınan Grafikleri El ile Yönetme.
Aşağıdaki kod BufferedGraphics örneğinde gösterildiği gibi Allocate yöntemini çağırarak sınıfının bir örneğini oluşturun.
// 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)özelliğini ayarerek grafik arabelleğine grafik Graphics çizin. Örneğin:
// 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)Grafik arabelleğine tüm çizim işlemlerinizi tamamlandıktan sonra, aşağıdaki kod örneğinde gösterildiği gibi arabelleği işlemek için yöntemini bu arabellekle ilişkili çizim yüzeyine veya belirtilen çizim yüzeyine Render çağrı yapın.
// 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)Grafik işlemeyi bitirdikten sonra sistem
Disposekaynaklarını serbest bırakarak BufferedGraphics örnekte yöntemini arayın.myBuffer.Dispose();myBuffer.Dispose()