WriteableBitmap.AddDirtyRect(Int32Rect) Méthode

Définition

Spécifie la zone de la bitmap qui a été modifiée.

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)

Paramètres

dirtyRect
Int32Rect

Int32Rect représentant la zone qui a été modifiée. Les dimensions sont en pixels.

Attributs

Exceptions

La bitmap n'a pas été verrouillée par un appel à la méthode Lock() ou TryLock(Duration).

dirtyRect est en dehors des limites du WriteableBitmap.

Exemples

L’exemple de code suivant montre comment spécifier la zone de la mémoire tampon arrière qui a été modifiée à l’aide de la AddDirtyRect méthode .

    // 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();
        }
    }

Remarques

Appelez la AddDirtyRect méthode pour indiquer les modifications apportées par votre code à la mémoire tampon arrière.

Lorsque vous appelez cette méthode plusieurs fois, les zones modifiées sont accumulées dans une représentation suffisante, mais pas nécessairement minimale. Pour plus d’efficacité, seules les zones marquées comme étant sales sont garanties d’être copiées vers la mémoire tampon avant. Toutefois, n’importe quelle partie de la bitmap peut être copiée vers l’avant, vous devez donc vous assurer que l’intégralité de la mémoire tampon arrière est toujours valide.

Appelez la AddDirtyRect méthode uniquement entre les appels aux Lock méthodes et Unlock , comme décrit dans les remarques de classe WriteableBitmap .

S’applique à