WriteableBitmap.AddDirtyRect(Int32Rect) Méthode

Définition

Spécifie la zone de la bitmap qui a changé.

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

Représentant Int32Rect la zone qui a changé. Les dimensions sont en pixels.

Attributs

Exceptions

La bitmap n’a pas été verrouillée par un appel aux méthodes ou Lock() aux TryLock(Duration) méthodes.

dirtyRect se trouve à l’extérieur des limites du WriteableBitmap.

Exemples

L’exemple de code suivant montre comment spécifier la zone de la mémoire tampon back qui a changé à 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 à votre code dans la mémoire tampon back.

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 sales sont garanties d’être copiées vers la mémoire tampon frontale. Toutefois, toute 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 back est toujours valide.

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

S’applique à