BitmapDataFactoryCreateBitmapData(IntPtr, Size, Int32, PixelFormatInfo, FuncICustomBitmapDataRow, Int32, Color32, ActionICustomBitmapDataRow, Int32, Color32, WorkingColorSpace, Color32, Byte, Action) Method

Creates an IReadWriteBitmapData instance with a custom non-indexed pixel format wrapping an unmanaged 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 CreateBitmapData(IntPtr, Size, 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#
[SecurityCriticalAttribute]
public static IReadWriteBitmapData CreateBitmapData(
	IntPtr buffer,
	Size size,
	int stride,
	PixelFormatInfo pixelFormatInfo,
	Func<ICustomBitmapDataRow, int, Color32>? rowGetColor,
	Action<ICustomBitmapDataRow, int, Color32>? rowSetColor,
	WorkingColorSpace workingColorSpace,
	Color32 backColor = default,
	byte alphaThreshold = 128,
	Action? disposeCallback = null
)

Parameters

buffer  IntPtr
The memory address to be used as the underlying buffer for the returned IReadWriteBitmapData. Make sure there is enough allocated memory for the specified size, stride and pixelFormatInfo; otherwise, accessing pixels may corrupt memory or throw an AccessViolationException. If it points to managed memory make sure it is pinned until the returned bitmap data is disposed.
size  Size
The size of the bitmap data to create in pixels.
stride  Int32
The size of a row in bytes. It allows to have some padding at the end of each row. It can be negative for bottom-up layout (ie. when buffer points to the first pixel of the bottom row).
pixelFormatInfo  PixelFormatInfo
A PixelFormatInfo instance that describes the pixel format.
rowGetColor  FuncICustomBitmapDataRow, 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 CreateBitmapData(IntPtr, Size, Int32, CustomBitmapDataConfig) overload instead. If , then the returned instance will be write-only (can be cast to IWritableBitmapData).
rowSetColor  ActionICustomBitmapDataRow, 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 CreateBitmapData(IntPtr, Size, Int32, CustomBitmapDataConfig) overload instead. If , then the returned instance will be read-only (can be cast to IReadableBitmapData).
workingColorSpace  WorkingColorSpace
Specifies the preferred color space that should be used when working with the result bitmap data.
See the Remarks section of the WorkingColorSpace enumeration for more details.
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: .

Return Value

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

Exceptions

ArgumentNullExceptionbuffer is IntPtr.Zero
-or-
Both rowGetColor and rowSetColor are .
ArgumentOutOfRangeExceptionsize has a zero or negative width or height
-or-
The absolute value of stride is too small for the specified width and pixelFormatInfo
-or-
workingColorSpace is not one of the defined values.
ArgumentExceptionpixelFormatInfo is indexed or its BitsPerPixel is 0.

See Also