Class ImageBufferExtensionsSystemWindowsMedia

Contains extension methods for ImageBuffer for interop with the System.Windows.Media library.

Inheritance
ImageBufferExtensionsSystemWindowsMedia
Namespace: ic4
Assembly: ic4dotnet.System.Windows.Media.dll
Syntax
public static class ImageBufferExtensionsSystemWindowsMedia
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 BitmapSource object System.Windows.Media.Imaging.BitmapSource bmp = imageBuffer.CreateBitmapSourceCopy();

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

// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Create copy in a BitmapSource object
System.Windows.Media.Imaging.BitmapSource bmp = ImageBufferExtensionsSystemWindowsMedia.CreateBitmapSourceCopy(imageBuffer);

Methods

CopyTo(ImageBuffer, WriteableBitmap)

Copies the contents of the passed ImageBuffer into the passed WriteableBitmap.

Declaration
public static void CopyTo(this ImageBuffer buffer, WriteableBitmap bmp)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

WriteableBitmap bmp

A destination bitmap

The Format of the bitmap must be one of the following:
Remarks

If the pixel format of the source image buffer and the format of the destination bitmap is not a perfect match, a conversion operation occurs. For example, bayer raw data can be converted to RGB.

Exceptions
Type Condition
ArgumentNullException

buffer is null or bmp is null

ArgumentException

The passed image buffer and bitmap did not have the same dimensions

NotSupportedException

The pixel format of the bitmap specified by bmp is not supported.

CreateBitmapSourceCopy(ImageBuffer, double, double)

Creates a new BitmapSource containing a copy of the image data of the passed image buffer.

Declaration
public static BitmapSource CreateBitmapSourceCopy(this ImageBuffer buffer, double dpiX = 96, double dpiY = 96)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

double dpiX

The value to be set in DpiX

double dpiY

The value to be set in DpiY

Returns
Type Description
BitmapSource

A BitmapSource containing a copy of the image data of the passed image buffer.

Exceptions
Type Condition
ArgumentNullException

buffer is null

NotSupportedException

The pixel format of the passed image buffer is not supported.

CreateCompatibleWritableBitmap(ImageBuffer, double, double)

Creates a WriteableBitmap with a format that the image buffer's contents can be copied or converted into.

Declaration
public static WriteableBitmap CreateCompatibleWritableBitmap(this ImageBuffer buffer, double dpiX = 96, double dpiY = 96)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

double dpiX

The value to be set in DpiX

double dpiY

The value to be set in DpiY

Returns
Type Description
WriteableBitmap

A WriteableBitmap that can be used as the target of a CopyTo(ImageBuffer, WriteableBitmap) operation.

Exceptions
Type Condition
ArgumentNullException

buffer is null

NotSupportedException

The pixel format of the passed image buffer is not supported.