WriteableBitmap.WritePixels Method

Definition

Updates the pixels of the writeable bitmap.

Overloads

WritePixels(Int32Rect, Array, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

WritePixels(Int32Rect, IntPtr, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

WritePixels(Int32Rect, Array, Int32, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

WritePixels(Int32Rect, IntPtr, Int32, Int32, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

WritePixels(Int32Rect, Array, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

C#
[System.Security.SecurityCritical]
public void WritePixels(System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset);
C#
public void WritePixels(System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset);

Parameters

sourceRect
Int32Rect

The rectangle of the WriteableBitmap to update.

pixels
Array

The pixel array used to update the bitmap.

stride
Int32

The stride of the update region in pixels.

offset
Int32

The input buffer offset.

Attributes

Exceptions

One or more of the following conditions is true.

sourceRect falls outside the bounds of the WriteableBitmap.

stride < 1

offset < 0

pixels is null.

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

Examples

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

C#
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);
}

Remarks

The WritePixels(Int32Rect, Array, Int32, Int32, Int32) and WritePixels(Int32Rect, IntPtr, Int32, Int32, Int32, Int32) overloads are preferred over using this method.

Note

In partial trust, use the WritePixels(Int32Rect, Array, Int32, Int32, Int32) overload.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

WritePixels(Int32Rect, IntPtr, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

C#
[System.Security.SecurityCritical]
public void WritePixels(System.Windows.Int32Rect sourceRect, IntPtr buffer, int bufferSize, int stride);
C#
public void WritePixels(System.Windows.Int32Rect sourceRect, IntPtr buffer, int bufferSize, int stride);

Parameters

sourceRect
Int32Rect

The rectangle of the WriteableBitmap to update.

buffer
IntPtr

The input buffer used to update the bitmap.

bufferSize
Int32

The size of the input buffer.

stride
Int32

The stride of the update region in buffer.

Attributes

Exceptions

One or more of the following conditions is true.

sourceRect falls outside the bounds of the WriteableBitmap.

bufferSize < 1

stride < 1

buffer is null.

Remarks

The WritePixels(Int32Rect, Array, Int32, Int32, Int32) and WritePixels(Int32Rect, IntPtr, Int32, Int32, Int32, Int32) overloads are preferred over using this method.

Note

In partial trust, use the WritePixels(Int32Rect, Array, Int32, Int32, Int32) overload.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

WritePixels(Int32Rect, Array, Int32, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

C#
[System.Security.SecurityCritical]
public void WritePixels(System.Windows.Int32Rect sourceRect, Array sourceBuffer, int sourceBufferStride, int destinationX, int destinationY);
C#
public void WritePixels(System.Windows.Int32Rect sourceRect, Array sourceBuffer, int sourceBufferStride, int destinationX, int destinationY);

Parameters

sourceRect
Int32Rect

The rectangle in sourceBuffer to copy.

sourceBuffer
Array

The input buffer used to update the bitmap.

sourceBufferStride
Int32

The stride of the input buffer, in bytes.

destinationX
Int32

The destination x-coordinate of the left-most pixel in the back buffer.

destinationY
Int32

The destination y-coordinate of the top-most pixel in the back buffer.

Attributes

Exceptions

One or more of the following conditions is true.

sourceRect falls outside the bounds of the WriteableBitmap.

destinationX or destinationY is outside the bounds of the WriteableBitmap.

sourceBufferStride < 1

sourceBuffer is null.

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

Remarks

Call the WritePixels method to update the WriteableBitmap automatically with the contents of sourceBuffer. Calling this method is the equivalent of using the Lock and Unlock workflow described in the WriteableBitmap class remarks.

Note

Use this overload in partial trust.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

WritePixels(Int32Rect, IntPtr, Int32, Int32, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

C#
[System.Security.SecurityCritical]
public void WritePixels(System.Windows.Int32Rect sourceRect, IntPtr sourceBuffer, int sourceBufferSize, int sourceBufferStride, int destinationX, int destinationY);
C#
public void WritePixels(System.Windows.Int32Rect sourceRect, IntPtr sourceBuffer, int sourceBufferSize, int sourceBufferStride, int destinationX, int destinationY);

Parameters

sourceRect
Int32Rect

The rectangle in sourceBuffer to copy.

sourceBuffer
IntPtr

The input buffer used to update the bitmap.

sourceBufferSize
Int32

The size of the input buffer.

sourceBufferStride
Int32

The stride of the input buffer, in bytes.

destinationX
Int32

The destination x-coordinate of the left-most pixel in the back buffer.

destinationY
Int32

The destination y-coordinate of the top-most pixel in the back buffer.

Attributes

Exceptions

One or more of the following conditions is true.

sourceRect falls outside the bounds of the WriteableBitmap.

destinationX or destinationY is outside the bounds of the WriteableBitmap.

sourceBufferSize < 1

sourceBufferStride < 1

sourceBuffer is null.

Remarks

Call the WritePixels method to update the WriteableBitmap automatically with the contents of sourceBuffer. Calling this method is the equivalent of using the Lock and Unlock workflow described in the WriteableBitmap class remarks.

Note

In partial trust, use the WritePixels(Int32Rect, Array, Int32, Int32, Int32) overload.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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