IWritableBitmapDataWriteRawT Method
Sets the underlying raw value within the current
IWritableBitmapData at the specified coordinates.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
void WriteRaw<T>(
int x,
int y,
T data
)
where T : struct, new()
Sub WriteRaw(Of T As {Structure, New}) (
x As Integer,
y As Integer,
data As T
)
generic<typename T>
where T : value class, gcnew()
void WriteRaw(
int x,
int y,
T data
)
abstract WriteRaw :
x : int *
y : int *
data : 'T -> unit when 'T : struct, new()
- x Int32
- The x-coordinate of the value to write. The valid range depends on the size of T.
- y Int32
- The y-coordinate of the value to write.
- data T
- The raw value to write.
- T
- 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 this IWritableBitmapData instance.
To determine the actual pixel size use the PixelFormat property of this IWritableBitmapData instance.
If
T is a primitive type of size greater than 1 byte (for example
int,
float, etc.),
then the address determined by the coordinates should be aligned to the size of
T. On most platforms misalignment affects only performance,
but depending on the architecture, the operation may have an unexpected result, or even a
DataMisalignedException can be thrown.
The following example demonstrates how to write multiple pixels by a single
WriteRaw call:
using IReadWriteBitmapData bmp4bppIndexed = BitmapDataFactory.CreateBitmapData(4, 4, KnownPixelFormat.Format4bppIndexed);
using IReadWriteBitmapData bitmapData = bmp4bppIndexed.GetReadWriteBitmapData();
// Writing as uint writes 8 pixels at once in case of a 4 BPP indexed bitmap:
bitmapData.WriteRaw<uint>(0, 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++)
Console.WriteLine(bitmapData.GetColorIndex(x, 0));
See also the example at the
Examples section of the
IReadableBitmapData.ReadRaw 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. |