WriteableBitmap.AddDirtyRect(Int32Rect) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger området för bitmappen som ändrades.
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)
Parametrar
- dirtyRect
- Int32Rect
Ett Int32Rect som representerar det område som ändrades. Dimensioner finns i bildpunkter.
- Attribut
Undantag
Bitmappen har inte låsts av ett anrop till Lock() metoderna eller TryLock(Duration) .
dirtyRect faller utanför gränserna för WriteableBitmap.
Exempel
I följande kodexempel visas hur du anger området för den bakåtbuffert som ändrades med hjälp AddDirtyRect av metoden.
// 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();
}
}
Kommentarer
AddDirtyRect Anropa metoden för att ange ändringar som koden har gjort i serverbufferten.
När du anropar den här metoden flera gånger ackumuleras de ändrade områdena i en tillräcklig, men inte nödvändigtvis minimal, representation. För effektivitet är det bara de områden som är markerade som smutsiga som garanterat kopieras framåt till den främre bufferten. Alla delar av bitmappen kan dock kopieras framåt, så du måste se till att hela backbufferten alltid är giltig.
AddDirtyRect Anropa metoden endast mellan anrop till Lock metoderna och Unlock enligt beskrivningen i klasskommentarernaWriteableBitmap.