WriteableBitmap.Unlock Méthode

Définition

Libère la mémoire tampon de retour pour la rendre disponible pour l’affichage.

public:
 void Unlock();
[System.Security.SecurityCritical]
public void Unlock();
public void Unlock();
[<System.Security.SecurityCritical>]
member this.Unlock : unit -> unit
member this.Unlock : unit -> unit
Public Sub Unlock ()
Attributs

Exceptions

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

Exemples

L’exemple de code suivant montre comment libérer la mémoire tampon arrière à l’aide de la Unlock 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

La Unlock méthode décrémente le nombre de verrous. Lorsque le nombre de verrous atteint 0, une passe de rendu est demandée si la AddDirtyRect méthode a été appelée.

S’applique à

Voir aussi