共用方式為


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) 方法鎖定點陣圖。

dirtyRect 落在 WriteableBitmap 範圍之外。

範例

下列程式碼範例示範如何使用 方法來指定已變更 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請只在 對 和 Unlock 方法的 Lock 呼叫之間呼叫 方法,如類別備註中所述 WriteableBitmap

適用於