如何:手動管理已緩衝的圖形
針對更進階的雙重緩衝案例,您可以使用 .NET Framework 類別來實作您自己的雙緩衝邏輯。 負責配置和管理個別圖形緩衝區的類別是 BufferedGraphicsContext 類別。 每個應用程式都有自己的預設值 BufferedGraphicsContext ,可管理該應用程式的所有預設雙重緩衝處理。 您可以呼叫 來擷取這個實例的 Current 參考。
取得預設 BufferedGraphicsCoNtext 的參考
Current設定 屬性,如下列程式碼範例所示。
BufferedGraphicsContext myContext; myContext = BufferedGraphicsManager.Current;
Dim myContext As BufferedGraphicsContext myContext = BufferedGraphicsManager.Current
注意
您不需要在從 BufferedGraphicsManager 類別收到的參考上 BufferedGraphicsContext 呼叫
Dispose
方法。 會 BufferedGraphicsManager 處理預設 BufferedGraphicsContext 實例的所有記憶體配置和散發。對於動畫等圖形密集型應用程式,您有時可以使用專用 BufferedGraphicsContext 而非 BufferedGraphicsContext 提供的 BufferedGraphicsManager 來改善效能。 這可讓您個別建立和管理圖形緩衝區,而不會造成管理與應用程式相關聯的所有其他緩衝圖形的效能額外負荷,不過應用程式耗用的記憶體將會更大。
建立專用的 BufferedGraphicsCoNtext
宣告並建立 類別的新實例 BufferedGraphicsContext ,如下列程式碼範例所示。
BufferedGraphicsContext myContext; myContext = new BufferedGraphicsContext(); // Insert code to create graphics here. // On a non-default BufferedGraphicsContext instance, you should always // call Dispose when finished. myContext.Dispose();
Dim myContext As BufferedGraphicsContext myContext = New BufferedGraphicsContext ' Insert code to create graphics here. ' On a nondefault BufferedGraphicsContext instance, you should always ' call Dispose when finished. myContext.Dispose()