WriteableBitmap.AddDirtyRect(Int32Rect) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定所變更之點陣圖的區域。
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)
參數
- 屬性
例外狀況
尚未呼叫 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 。