BitmapDataFactoryCreateBitmapDataT(T, Size, Int32, CustomIndexedBitmapDataConfig) Method
Creates an
IReadWriteBitmapData instance with a custom 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,
CustomIndexedBitmapDataConfig 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 CustomIndexedBitmapDataConfig
) As IReadWriteBitmapData
public:
generic<typename T>
where T : value class, gcnew()
static IReadWriteBitmapData^ CreateBitmapData(
array<T>^ buffer,
Size size,
int stride,
CustomIndexedBitmapDataConfig^ customBitmapDataConfig
)
static member CreateBitmapData :
buffer : 'T[] *
size : Size *
stride : int *
customBitmapDataConfig : CustomIndexedBitmapDataConfig -> 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, PixelFormatInfo, FuncICustomBitmapDataRowT, Int32, Int32, ActionICustomBitmapDataRowT, Int32, Int32, Palette, FuncPalette, Boolean, Action) 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 CustomIndexedBitmapDataConfig
- The configuration for the custom pixel format. Either the getter or the 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 indexed pixel format. You need to specify a PixelFormatInfo
and at one or both pixel accessor delegates to be called whenever a pixel is get or set. In this overload these can be done by assigning a CustomIndexedBitmapDataConfig
instance to the customBitmapDataConfig parameter. The desired indexed PixelFormatInfo should be set in the PixelFormat
property, whereas the getter and setter methods can be assigned to the RowGetColorIndex and RowSetColorIndex properties, respectively.
An indexed custom pixel format can have any BitsPerPixel value between 1 and 16. A typical bits-per-pixel value is a power of two and is not greater than 8;
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.
If the Palette property in customBitmapDataConfig is , then the closest not larger system palette will be used,
possibly completed with transparent entries. For example, if PixelFormatInfo.BitsPerPixel is 9
and Palette is , then a Palette with 512 colors will be created where the first 256 colors will be the same
as in SystemDefault8BppPalette.
For that reason it is always recommended to set the
Palette property, especially if it has fewer entries than the possible allowed maximum
because replacing the palette afterwards by the
TrySetPalette extension method allows only to set a palette that has no
fewer entries. It's because the
TrySetPalette method assumes that the underlying buffer might already have pixels whose
indices may turn invalid with a smaller palette.