WriteableBitmap.AddDirtyRect(Int32Rect) Método

Definición

Especifica el área del mapa de bits que cambió.

public:
 void AddDirtyRect(System::Windows::Int32Rect dirtyRect);
[System.Security.SecurityCritical]
public void AddDirtyRect(System.Windows.Int32Rect dirtyRect);
[<System.Security.SecurityCritical>]
member this.AddDirtyRect : System.Windows.Int32Rect -> unit
Public Sub AddDirtyRect (dirtyRect As Int32Rect)

Parámetros

dirtyRect
Int32Rect

que Int32Rect representa el área que cambió. Las dimensiones están en píxeles.

Atributos

Excepciones

El mapa de bits no se ha bloqueado mediante una llamada a los Lock() métodos o TryLock(Duration) .

dirtyRect cae fuera de los límites de WriteableBitmap.

Ejemplos

En el ejemplo de código siguiente se muestra cómo especificar el área del búfer de reserva que cambió mediante el AddDirtyRect método .

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

Comentarios

Llame al AddDirtyRect método para indicar los cambios realizados en el código en el búfer de reserva.

Cuando se llama a este método varias veces, las áreas modificadas se acumulan en una representación suficiente, pero no necesariamente mínima. Para mejorar la eficacia, solo se garantiza que las áreas marcadas como sucias se copien hacia delante en el búfer frontal. Sin embargo, cualquier parte del mapa de bits se puede copiar hacia delante, por lo que debe asegurarse de que todo el búfer de reserva siempre es válido.

Llame al AddDirtyRect método solo entre las llamadas a los Lock métodos y Unlock , como se describe en los comentarios de clase WriteableBitmap .

Se aplica a