方法: バッファリングされたグラフィックスを手動で管理する

より高度なダブル バッファリングのシナリオでは、.NET Framework クラスを使用して独自のダブル バッファリング ロジックを実装できます。 個々のグラフィックス バッファーの割り当てと管理を担当するクラスは BufferedGraphicsContext クラスです。 各アプリケーション ドメインには、そのアプリケーションの既定のダブル バッファリングをすべて管理する、それぞれ独自の既定の BufferedGraphicsContext インスタンスがあります。 このインスタンスへの参照は、Current を呼び出すことで取得できます。

既定の BufferedGraphicsContext への参照を取得するには

  • 次のコード例に示すように、Current プロパティを設定します。

    BufferedGraphicsContext myContext;
    myContext = BufferedGraphicsManager.Current;
    
    Dim myContext As BufferedGraphicsContext
    myContext = BufferedGraphicsManager.Current
    
    

    注意

    BufferedGraphicsManager クラスから受け取る BufferedGraphicsContext 参照に対して Dispose メソッドを呼び出す必要はありません。 BufferedGraphicsManager では、既定の BufferedGraphicsContext インスタンスのメモリ割り当てと配分がすべて処理されます。

    アニメーションなど、グラフィックを多用するアプリケーションの場合は、BufferedGraphicsManager によって提供される BufferedGraphicsContext ではなく、専用の BufferedGraphicsContext を使用することで、パフォーマンスを向上させることができます。 これにより、アプリケーションに関連付けられているその他すべてのバッファリング済みグラフィックスを管理するためのパフォーマンス オーバーヘッドを発生させることなく、グラフィックス バッファーを個別に作成して管理することができます。ただし、アプリケーションで使用されるメモリの量は多くなります。

専用の 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()
    
    

関連項目