WriteableBitmap.Unlock Método

Definición

Libera el búfer de reserva de modo que esté disponible para la presentación.

C#
[System.Security.SecurityCritical]
public void Unlock();
C#
public void Unlock();
Atributos

Excepciones

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

Ejemplos

En el ejemplo de código siguiente se muestra cómo liberar el búfer de reserva mediante el Unlock método .

C#
    // 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

El Unlock método disminuye el recuento de bloqueos. Cuando el recuento de bloqueos alcanza 0, se solicita un pase de representación si se ha llamado al AddDirtyRect método .

Se aplica a

Produto Versións
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Consulte también