WriteableBitmap.AddDirtyRect(Int32Rect) メソッド

定義

変更されるビットマップの領域を指定します。

public:
 void AddDirtyRect(System::Windows::Int32Rect dirtyRect);
[System.Security.SecurityCritical]
public void AddDirtyRect (System.Windows.Int32Rect dirtyRect);
public void AddDirtyRect (System.Windows.Int32Rect dirtyRect);
[<System.Security.SecurityCritical>]
member this.AddDirtyRect : System.Windows.Int32Rect -> unit
member this.AddDirtyRect : System.Windows.Int32Rect -> unit
Public Sub AddDirtyRect (dirtyRect As Int32Rect)

パラメーター

dirtyRect
Int32Rect

変更される領域を表す Int32Rect。 次元はピクセル単位です。

属性

例外

Lock() メソッドまたは TryLock(Duration) メソッドへの呼び出しによりロックされなかったビットマップ。

dirtyRectWriteableBitmap の境界の外側にあります。

次のコード例は、メソッドを使用して変更されたバック バッファーの領域を指定する方法を AddDirtyRect 示しています。

    // The DrawPixel method updates the WriteableBitmap by using
    // unsafe code to write a pixel into the back buffer.
    static void DrawPixel(MouseEventArgs e)
    {
        int column = (int)e.GetPosition(i).X;
        int row = (int)e.GetPosition(i).Y;

        try{
            // Reserve the back buffer for updates.
            writeableBitmap.Lock();

            unsafe
            {
                // Get a pointer to the back buffer.
                IntPtr pBackBuffer = writeableBitmap.BackBuffer;

                // Find the address of the pixel to draw.
                pBackBuffer += row * writeableBitmap.BackBufferStride;
                pBackBuffer += column * 4;

                // Compute the pixel's color.
                int color_data = 255 << 16; // R
                color_data |= 128 << 8;   // G
                color_data |= 255 << 0;   // B

                // Assign the color data to the pixel.
                *((int*) pBackBuffer) = color_data;
            }

            // Specify the area of the bitmap that changed.
            writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1));
        }
        finally{
            // Release the back buffer and make it available for display.
            writeableBitmap.Unlock();
        }
    }

注釈

メソッドを AddDirtyRect 呼び出して、コードがバック バッファーに加えた変更を示します。

このメソッドを複数回呼び出すと、変更された領域は十分に蓄積されますが、必ずしも最小限の表現ではありません。 効率を高めるために、ダーティとしてマークされている領域のみが、フロント バッファーに前方にコピーすることが保証されます。 ただし、ビットマップの任意の部分を前方にコピーできるため、バック バッファー全体が常に有効であることを確認する必要があります。

クラスの注釈で AddDirtyRect 説明されているように、メソッドとメソッドの Lock 呼び出し Unlock の間でのみメソッドを WriteableBitmap 呼び出します。

適用対象