Modifica

Condividi tramite


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.

public:
 void WritePixels(System::Windows::Int32Rect sourceRect, Array ^ pixels, int stride, int offset);
[System.Security.SecurityCritical]
public void WritePixels (System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset);
public void WritePixels (System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset);
[<System.Security.SecurityCritical>]
member this.WritePixels : System.Windows.Int32Rect * Array * int * int -> unit
member this.WritePixels : System.Windows.Int32Rect * Array * int * int -> unit
Public Sub WritePixels (sourceRect As Int32Rect, pixels As Array, stride As Integer, offset As Integer)

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.

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

WritePixels(Int32Rect, IntPtr, Int32, Int32)

Updates the pixels in the specified region of the bitmap.

public:
 void WritePixels(System::Windows::Int32Rect sourceRect, IntPtr buffer, int bufferSize, int stride);
[System.Security.SecurityCritical]
public void WritePixels (System.Windows.Int32Rect sourceRect, IntPtr buffer, int bufferSize, int stride);
public void WritePixels (System.Windows.Int32Rect sourceRect, IntPtr buffer, int bufferSize, int stride);
[<System.Security.SecurityCritical>]
member this.WritePixels : System.Windows.Int32Rect * nativeint * int * int -> unit
member this.WritePixels : System.Windows.Int32Rect * nativeint * int * int -> unit
Public Sub WritePixels (sourceRect As Int32Rect, buffer As IntPtr, bufferSize As Integer, stride As Integer)

Parameters

sourceRect
Int32Rect

The rectangle of the WriteableBitmap to update.

buffer
IntPtr

nativeint

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

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

Updates the pixels in the specified region of the bitmap.

public:
 void WritePixels(System::Windows::Int32Rect sourceRect, Array ^ sourceBuffer, int sourceBufferStride, int destinationX, int destinationY);
[System.Security.SecurityCritical]
public void WritePixels (System.Windows.Int32Rect sourceRect, Array sourceBuffer, int sourceBufferStride, int destinationX, int destinationY);
public void WritePixels (System.Windows.Int32Rect sourceRect, Array sourceBuffer, int sourceBufferStride, int destinationX, int destinationY);
[<System.Security.SecurityCritical>]
member this.WritePixels : System.Windows.Int32Rect * Array * int * int * int -> unit
member this.WritePixels : System.Windows.Int32Rect * Array * int * int * int -> unit
Public Sub WritePixels (sourceRect As Int32Rect, sourceBuffer As Array, sourceBufferStride As Integer, destinationX As Integer, destinationY As Integer)

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

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

Updates the pixels in the specified region of the bitmap.

public:
 void WritePixels(System::Windows::Int32Rect sourceRect, IntPtr sourceBuffer, int sourceBufferSize, int sourceBufferStride, int destinationX, int destinationY);
[System.Security.SecurityCritical]
public void WritePixels (System.Windows.Int32Rect sourceRect, IntPtr sourceBuffer, int sourceBufferSize, int sourceBufferStride, int destinationX, int destinationY);
public void WritePixels (System.Windows.Int32Rect sourceRect, IntPtr sourceBuffer, int sourceBufferSize, int sourceBufferStride, int destinationX, int destinationY);
[<System.Security.SecurityCritical>]
member this.WritePixels : System.Windows.Int32Rect * nativeint * int * int * int * int -> unit
member this.WritePixels : System.Windows.Int32Rect * nativeint * int * int * int * int -> unit
Public Sub WritePixels (sourceRect As Int32Rect, sourceBuffer As IntPtr, sourceBufferSize As Integer, sourceBufferStride As Integer, destinationX As Integer, destinationY As Integer)

Parameters

sourceRect
Int32Rect

The rectangle in sourceBuffer to copy.

sourceBuffer
IntPtr

nativeint

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