Class ImageBufferExtensionsSystemDrawing

Contains extension methods for ImageBuffer for interop with the System.Drawing library.

Inheritance

ImageBufferExtensionsSystemDrawing
Namespace: ic4
Assembly: ic4dotnet.System.Drawing.dll
Syntax
public static class ImageBufferExtensionsSystemDrawing
Examples

Since the members are extension methods, they can be called both explicitly and on image buffers directly, as if they were member functions.

To call it as a member function, a using directive has to exist for the ic4 namespace:

using ic4;

// (...) // Get image buffer from somewhere ImageBuffer imageBuffer = GetImageBuffer(); // Create copy in a System.Drawing.Bitmap object System.Drawing.Bitmap bmp = imageBuffer.CreateBitmapCopy();

Although not preferred, the function can also be called explicitly:

// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Create copy in a System.Drawing.Bitmap object
System.Drawing.Bitmap bmp = imageBuffer.CreateBitmapCopy(imageBuffer);

Methods

CreateBitmapCopy(ImageBuffer)

Creates a copy of the image buffer and stores it in a Bitmap.

Declaration

public static Bitmap CreateBitmapCopy(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
Bitmap

A Bitmap containing a copy of the image data in the passed image buffer.

Exceptions

Type Condition
ArgumentNullException

buffer is null

NotSupportedException

The pixel format of the image buffer is not supported.

CreateBitmapWrap(ImageBuffer)

Wraps the passed image buffer in a Bitmap.

Declaration

public static Bitmap CreateBitmapWrap(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
Bitmap

A Bitmap using the image buffer's memory as pixel storage.

Remarks

The returned bitmap becomes invalid when the image buffer is disposed.

Exceptions

Type Condition
ArgumentNullException

buffer is null

NotSupportedException

Data of the image buffer's pixel format cannot be wrapped in a Bitmap

IsBitmapWrapSupported(ImageBuffer)

Checks whether CreateBitmapWrap(ImageBuffer) can work on the image buffer's pixel format.

Declaration

public static bool IsBitmapWrapSupported(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
bool

true, if the contents of the image buffer can be wrapped in a Bitmap, otherwise false.

Remarks

Wrapping the contents of an image buffer in a Bitmap is only possible if the pixel format is one of the following:

Exceptions

Type Condition
ArgumentNullException

buffer is null