WriteableBitmap.AddDirtyRect(Int32Rect) Método

Definição

Especifica a área do bitmap que foi alterada.

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)

Parâmetros

dirtyRect
Int32Rect

Um Int32Rect que representa a área que foi alterada. As dimensões estão em pixels.

Atributos

Exceções

O bitmap não foi bloqueado por uma chamada aos métodos Lock() ou TryLock(Duration).

dirtyRect está fora dos limites do WriteableBitmap.

Exemplos

O exemplo de código a seguir mostra como especificar a área do buffer traseiro que foi alterada usando o 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();
        }
    }

Comentários

Chame o AddDirtyRect método para indicar as alterações feitas pelo código no buffer de fundo.

Quando você chama esse método várias vezes, as áreas alteradas são acumuladas em uma representação suficiente, mas não necessariamente mínima. Para eficiência, apenas as áreas marcadas como sujas têm a garantia de serem copiadas para o buffer frontal. No entanto, qualquer parte do bitmap pode ser copiada para frente, portanto, você deve garantir que todo o buffer traseiro seja sempre válido.

Chame o AddDirtyRect método somente entre chamadas para os Lock métodos e Unlock , conforme descrito nas observações de WriteableBitmap classe.

Aplica-se a