IReadableBitmapDataRowReadRawT Method
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
T ReadRaw<T>(
int x
)
where T : struct, new()
Function ReadRaw(Of T As {Structure, New}) (
x As Integer
) As T
generic<typename T>
where T : value class, gcnew()
T ReadRaw(
int x
)
abstract ReadRaw :
x : int -> 'T when '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.
- T
- The type of the value to return. Must be a value type without managed references.
TThe 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 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.
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.
The following example demonstrates how to access the premultiplied color values of a bitmap data with premultiplied pixel format:
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[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]
See also the example at the
Examples section of the
IWritableBitmapDataRow.WriteRaw method.
| ArgumentOutOfRangeException | x 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. |