BitmapDataFactoryCreateBitmapDataT(T, Int32, PixelFormatInfo, FuncICustomBitmapDataRowT, Int32, Int32, ActionICustomBitmapDataRowT, Int32, Int32, Palette, FuncPalette, Boolean, Action) Method

Creates an IReadWriteBitmapData instance with a custom indexed pixel format for a preallocated two-dimensional array with the specified parameters. If you can ensure that the delegates don't capture buffer use the CreateBitmapDataT(T, Int32, CustomIndexedBitmapDataConfig) overload instead.
See the Remarks section of the CreateBitmapDataT(T, Size, Int32, CustomIndexedBitmapDataConfig) 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>(
	T[,] buffer,
	int pixelWidth,
	PixelFormatInfo pixelFormatInfo,
	Func<ICustomBitmapDataRow<T>, int, int>? rowGetColorIndex,
	Action<ICustomBitmapDataRow<T>, int, int>? rowSetColorIndex,
	Palette? palette = null,
	Func<Palette, bool>? trySetPaletteCallback = null,
	Action? disposeCallback = null
)
where T : struct, new()

Parameters

buffer  T
A preallocated array 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.
rowGetColorIndex  FuncICustomBitmapDataRowT, Int32, Int32
A delegate that can get the color index of a pixel in a row of the bitmap data. If , then the returned instance will be write-only (can be cast to IWritableBitmapData).
rowSetColorIndex  ActionICustomBitmapDataRowT, Int32, Int32
A delegate that can set the color index of a pixel in a row of the bitmap data. If , then the returned instance will be read-only (can be cast to IReadableBitmapData).
palette  Palette  (Optional)
Specifies the desired Palette of the returned IReadWriteBitmapData instance. It determines also the BackColor and AlphaThreshold properties of the result. This parameter is optional.
Default value: .
trySetPaletteCallback  FuncPalette, Boolean  (Optional)
A delegate to be called when the palette is attempted to be replaced by the TrySetPalette method. If buffer belongs to some custom bitmap implementation, it can be used to update its original palette. This parameter is optional.
Default value: .
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

ArgumentNullExceptionbuffer is .
-or-
Both rowGetColorIndex and rowSetColorIndex are .
ArgumentOutOfRangeExceptionpixelWidth is too large for the specified buffer and pixelFormatInfo.
ArgumentExceptionbuffer is empty
-or-
palette is too large for the specified pixelFormatInfo
-or-
pixelFormatInfo is not indexed or its BitsPerPixel is not between 1 and 16.

See Also