共用方式為


WriteableBitmap.Unlock 方法

定義

釋放背景緩衝區以供顯示使用。

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 ()
屬性

例外狀況

尚未呼叫 Lock()TryLock(Duration) 方法鎖定點陣圖。

範例

下列程式碼範例示範如何使用 方法來釋放背景緩衝區 Unlock

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

備註

方法 Unlock 會遞減鎖定計數。 當鎖定計數達到 0 時,如果 AddDirtyRect 呼叫 方法,則會要求轉譯階段。

適用於

另請參閱