IReadableBitmapDataRowReadRawT Method

Gets the underlying raw value within the current IReadableBitmapDataRow at the specified x coordinate.


Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.1.0
T ReadRaw<T>(
	int x
where T : struct, new()


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

Type Parameters

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

Return Value

The raw value within the current IReadableBitmapDataRow at the specified x coordinate.


This method returns the actual raw underlying data as arbitrary unmanaged value type (a value type is unmanaged if contains no managed references). T can have any size so you using this method can access multiple pixels or 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 IReadableBitmapData instance.


The following example demonstrates how to access the premultiplied color values of a bitmap data with premultiplied pixel format:


This example requires to reference the KGySoft.Drawing package. When targeting .NET 7 or later it can be executed on Windows only.
using (IReadWriteBitmapData bitmapData = BitmapDataFactory.CreateBitmapData(
    new Size(1, 1), KnownPixelFormat.Format32bppPArgb))
    // setting a white pixel with 50% alpha:
    bitmapData.SetPixel(0, 0, Color.FromArgb(128, 255, 255, 255));

    // reading the raw premultiplied color value:
    Console.WriteLine(bitmapData[0].ReadRaw<Color32>(0)); // 80808080 [A=128; R=128; G=128; B=128]

    // but reading it by the indexer (or by GetPixel/GetColor) transforms the color back:
    Console.WriteLine(bitmapData[0][0]); // 80FFFFFF [A=128; R=255; G=255; B=255]


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