WriteableBitmap.AddDirtyRect(Int32Rect) 메서드

정의

변경된 비트맵의 영역을 지정합니다.

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)

매개 변수

dirtyRect
Int32Rect

Int32Rect 변경된 영역을 나타내는 값입니다. 차원은 픽셀 단위입니다.

특성

예외

비트맵이 또는 Lock() 메서드 호출에 의해 잠기 TryLock(Duration) 지 않았습니다.

dirtyRect는 .의 범위를 벗어나는 경우 WriteableBitmap

예제

다음 코드 예제에서는 메서드를 사용하여 AddDirtyRect 변경된 백 버퍼의 영역을 지정하는 방법을 보여줍니다.

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

설명

메서드를 호출하여 코드가 AddDirtyRect 백 버퍼에 적용한 변경 내용을 나타냅니다.

이 메서드를 여러 번 호출하면 변경된 영역이 충분한 표현으로 누적되지만 반드시 최소한의 표현은 아닙니다. 효율성을 위해 더티로 표시된 영역만 전면 버퍼로 복사됩니다. 그러나 비트맵의 모든 부분이 앞으로 복사될 수 있으므로 전체 백 버퍼가 항상 유효한지 확인해야 합니다.

클래스 설명에 AddDirtyRect 설명된 대로 메서드와 Unlock 메서드 호출 간에 Lock 만 메서드를 WriteableBitmap 호출합니다.

적용 대상