IReadableBitmapDataReadRawT Method
Gets the underlying raw value within the current
IReadableBitmapData at the specified coordinates.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
T ReadRaw<T>(
int x,
int y
)
where T : struct, new()
Function ReadRaw(Of T As {Structure, New}) (
x As Integer,
y As Integer
) As T
generic<typename T>
where T : value class, gcnew()
T ReadRaw(
int x,
int y
)
abstract ReadRaw :
x : int *
y : int -> 'T when 'T : struct, new()
- 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.
- T
- The type of the value to return. Must be a value type without managed references.
TThe raw value within the current
IReadableBitmapData at the specified coordinates.
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.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]
See also the example at the
Examples section of the
IWritableBitmapData.WriteRaw method.
| ArgumentOutOfRangeException | x 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. |