IReadableBitmapDataReadRawT Method

Gets the underlying raw value within the current IReadableBitmapData at the specified coordinates.

See the online help for an example.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
C#
T ReadRaw<T>(
	int x,
	int y
)
where T : struct, new()

Parameters

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

Type Parameters

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

Return Value

T
The raw value within the current IReadableBitmapData at the specified coordinates.

Remarks

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 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.

  Caution

If T is a primitive type of size greater than 1 byte (for example int, float, etc.), then the address of the result should be aligned to the size of T. On most platforms misalignment affects only performance, but depending on the architecture, an unexpected result may be returned, or even a DataMisalignedException can be thrown.

Examples

The following example demonstrates how to access the premultiplied color values of a bitmap data with premultiplied pixel format:
C#
using IReadWriteBitmapData bitmapData = BitmapDataFactory.CreateBitmapData(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.ReadRaw<Color32>(0, 0)); // 80808080 [A=128; R=128; G=128; B=128]

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

Exceptions

ArgumentOutOfRangeExceptionx is less than zero or the calculated offset of the value (considering the size of T) at least partially exceeds the bounds of a row.
-or-
y is less than zero or is greater than or equal to Height.

See Also