IWritableBitmapDataRowWriteRawT Method

Sets the underlying raw value within the current IWritableBitmapDataRow at the specified x coordinate.


Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 7.0.0-preview.3
void WriteRaw<T>(
	int x,
	T data
where T : struct, new()


x  Int32
The x-coordinate of the value within the row to write. The valid range depends on the size of T.
data  T
The raw value to write.

Type Parameters

The type of the value to write. Must be a value type without managed references.


This method writes the actual raw underlying data. T can have any size so you by using this method you can write multiple pixels as well as individual color channels.

To determine the row width in bytes use the RowSize property of the parent IReadableBitmapData instance.

To determine the actual pixel size use the PixelFormat property of the parent IWritableBitmapData instance.


The following example demonstrates how to write multiple pixels by a single WriteRaw call:


This example requires to reference the KGySoft.Drawing package. When targeting .NET 7 or later it can be executed on Windows only.
using (Bitmap bmp4bppIndexed = new Bitmap(8, 1, PixelFormat.Format4bppIndexed))
using (IReadWriteBitmapData bitmapData = bmp4bppIndexed.GetReadWriteBitmapData())
    IReadWriteBitmapDataRow row = bitmapData[0];

    // Writing as uint writes 8 pixels at once in case of a 4 BPP indexed bitmap:
    row.WriteRaw<uint>(0, 0x12345678);

    // because of little endianness and 4 BPP pixel order the color indices will be printed
    // in the following order: 7, 8, 5, 6, 3, 4, 1, 2
    for (int x = 0; x < bitmapData.Width; x++)


ArgumentOutOfRangeExceptionx is less than zero or the memory location of the value (considering the size of T) at least partially exceeds the bounds of the current row.

See Also