BitmapDataFactoryCreateBitmapDataT(T, Size, Int32, CustomBitmapDataConfig) Method
Creates an
IReadWriteBitmapData instance with a custom non-indexed pixel format for a preallocated one dimensional array with the specified parameters.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.2.0
public static IReadWriteBitmapData CreateBitmapData<T>(
T[] buffer,
Size size,
int stride,
CustomBitmapDataConfig customBitmapDataConfig
)
where T : struct, new()
Public Shared Function CreateBitmapData(Of T As {Structure, New}) (
buffer As T(),
size As Size,
stride As Integer,
customBitmapDataConfig As CustomBitmapDataConfig
) As IReadWriteBitmapData
public:
generic<typename T>
where T : value class, gcnew()
static IReadWriteBitmapData^ CreateBitmapData(
array<T>^ buffer,
Size size,
int stride,
CustomBitmapDataConfig^ customBitmapDataConfig
)
static member CreateBitmapData :
buffer : 'T[] *
size : Size *
stride : int *
customBitmapDataConfig : CustomBitmapDataConfig -> IReadWriteBitmapData when 'T : struct, new()
- buffer T
- A preallocated array to be used as the underlying buffer for the returned IReadWriteBitmapData.
It can be larger than it is required for the specified parameters.
If the actual image data starts at some offset use the CreateBitmapDataT(ArraySectionT, Size, Int32, CustomBitmapDataConfig) overload instead.
- 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.
- customBitmapDataConfig CustomBitmapDataConfig
- The configuration for the custom pixel format. At least one getter or setter delegate must be specified.
If you can ensure that the delegates don't capture buffer make sure you set the BackBufferIndependentPixelAccess property to .
- T
- The type of the elements in buffer.
IReadWriteBitmapDataAn
IReadWriteBitmapData instance wrapping the specified
buffer and using the provided parameters.
This method allows creating an IReadWriteBitmapData instance with custom pixel format. You need to specify a PixelFormatInfo
and at least one delegate setter or getter delegate to be called whenever a pixel is get or set. In this overload these can be done by assigning a CustomBitmapDataConfig
instance to the customBitmapDataConfig parameter. The desired PixelFormatInfo should be set in the PixelFormat
property, whereas for the getter and setter methods you can select the ones with the color types that fit the best for your pixel format.
It is enough to set only one getter and/or setter with the best matching color type. For example, if you set the
RowGetColor64 property only,
which returns the pixels as
Color64 values, then all of the other pixel-reading methods will use this delegate and will convert the result from
Color64.
A custom pixel format can have any BitsPerPixel value between 1 and 128. A typical bits-per-pixel value is a power of two; however,
any other value can be used if you handle them in the provided delegates.
The getter and setter delegates are always called with an x coordinate meaning the pixel offset in the corresponding row.
It is highly recommended that the delegates do not use the
buffer directly (they don't capture the
buffer instance).
Instead, they should access the actual data using their
ICustomBitmapDataRow argument, which allows reading and writing raw data within the corresponding row, independently
from any specific buffer instance. If they do so, then you can set the
BackBufferIndependentPixelAccess to true in
customBitmapDataConfig,
which allows some operations work with better quality and performance.