BitmapDataFactoryCreateBitmapDataT(Array2DT, Int32, PixelFormatInfo, FuncICustomBitmapDataRowT, Int32, Color32, ActionICustomBitmapDataRowT, Int32, Color32, Color32, Byte, Action) Method

Creates an IReadWriteBitmapData instance with a custom non-indexed pixel format wrapping the specified buffer and using the specified parameters. By this overload you can specify a pair of custom getter/setter delegates using the Color32 color type. If other color types fit better for the custom format or you can ensure that the delegates don't capture buffer use the CreateBitmapDataT(Array2DT, Int32, CustomBitmapDataConfig) overload instead.
See the Remarks section of the CreateBitmapDataT(T, Size, Int32, CustomBitmapDataConfig) overload for details.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.2.0
C#
public static IReadWriteBitmapData CreateBitmapData<T>(
	Array2D<T> buffer,
	int pixelWidth,
	PixelFormatInfo pixelFormatInfo,
	Func<ICustomBitmapDataRow<T>, int, Color32>? rowGetColor,
	Action<ICustomBitmapDataRow<T>, int, Color32>? rowSetColor,
	Color32 backColor = default,
	byte alphaThreshold = 128,
	Action? disposeCallback = null
)
where T : struct, new()

Parameters

buffer  Array2DT
An Array2D<T> to be used as the underlying buffer for the returned IReadWriteBitmapData.
pixelWidth  Int32
The width of the bitmap data to create in pixels.
pixelFormatInfo  PixelFormatInfo
A PixelFormatInfo instance that describes the pixel format.
rowGetColor  FuncICustomBitmapDataRowT, Int32, Color32
A delegate that can get the 32-bit color of a pixel in a row of the bitmap data. If pixelFormatInfo represents a wider format it is recommended to use the CreateBitmapDataT(Array2DT, Int32, CustomBitmapDataConfig) overload instead. If , then the returned instance will be write-only (can be cast to IWritableBitmapData).
rowSetColor  ActionICustomBitmapDataRowT, Int32, Color32
A delegate that can set the color of a pixel from a Color32 value in a row of the bitmap data. If pixelFormatInfo represents a wider format it is recommended to use the CreateBitmapDataT(Array2DT, Int32, CustomBitmapDataConfig) overload instead. If , then the returned instance will be read-only (can be cast to IReadableBitmapData).
backColor  Color32  (Optional)
For pixel formats without alpha gradient support specifies the BackColor value of the returned IReadWriteBitmapData instance. It does not affect the actual returned bitmap content. See the Remarks section of the CreateBitmapData(Size, KnownPixelFormat, WorkingColorSpace, Color32, Byte) overload for details. The alpha value (Color32.A field) of the specified background color is ignored. This parameter is optional.
Default value: The default value of the Color32 type, which has the same RGB values as Black.
alphaThreshold  Byte  (Optional)
For pixel formats without alpha gradient support specifies the AlphaThreshold value of the returned IReadWriteBitmapData instance. See the Remarks section of the CreateBitmapData(Size, KnownPixelFormat, WorkingColorSpace, Color32, Byte) overload for details. This parameter is optional.
Default value: 128.
disposeCallback  Action  (Optional)
A delegate to be called when the returned IReadWriteBitmapData is disposed or finalized. This parameter is optional.
Default value: .

Type Parameters

T
The type of the elements in buffer.

Return Value

IReadWriteBitmapData
An IReadWriteBitmapData instance wrapping the specified buffer and using the provided parameters.

Exceptions

ArgumentNullExceptionThe IsNull property of buffer is .
-or-
Both rowGetColor and rowSetColor are .
ArgumentOutOfRangeExceptionpixelWidth is too large for the specified buffer and pixelFormatInfo.
ArgumentExceptionbuffer is empty
-or-
pixelFormatInfo is indexed or its BitsPerPixel is 0.

See Also