WriteableBitmap.WritePixels Method (Int32Rect, Array, Int32, Int32)

 

Updates the pixels in the specified region of the bitmap.

Namespace:   System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)

[SecurityCriticalAttribute]
public void WritePixels(
	Int32Rect sourceRect,
	Array pixels,
	int stride,
	int offset
)

Parameters

sourceRect
Type: System.Windows.Int32Rect

The rectangle of the WriteableBitmap to update.

pixels
Type: System.Array

The pixel array used to update the bitmap.

stride
Type: System.Int32

The stride of the update region in pixels.

offset
Type: System.Int32

The input buffer offset.

Exception Condition
ArgumentOutOfRangeException

One or more of the following conditions is true.

sourceRect falls outside the bounds of the WriteableBitmap.

stride < 1

offset < 0

ArgumentNullException

pixels is null.

ArgumentException

pixels has a rank other than 1 or 2, or its length is less than or equal to 0.

The following code example shows how to update a pixel in the back buffer by using the WritePixels method.

static void ErasePixel(MouseEventArgs e)
{
    byte[] ColorData = { 0, 0, 0, 0 }; // B G R

    Int32Rect rect = new Int32Rect(
            (int)(e.GetPosition(i).X), 
            (int)(e.GetPosition(i).Y), 
            1, 
            1);

    writeableBitmap.WritePixels( rect, ColorData, 4, 0);
}

SecurityPermission

for access to unmanaged resources. Security action: Demand. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

.NET Framework
Available since 3.0
Return to top
Show: