Class ImageBufferExtensions

Contains extension methods for ImageBuffer that allow saving image buffer contents into files of various file formats.

Inheritance
ImageBufferExtensions
Namespace: ic4
Assembly: ic4dotnet.dll
Syntax
public static class ImageBufferExtensions
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(); // Save image buffer as bitmap file imageBuffer.SaveAsbitmap("test.bmp");

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

// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Save image buffer as bitmap file
ImageBufferExtensions.SaveAsbitmap(imageBuffer, "test.bmp");

Methods

SaveAsBitmap(ImageBuffer, string, bool)

Saves an image buffer as a Bitmap file.

Declaration
public static void SaveAsBitmap(this ImageBuffer buffer, string filename, bool storeBayerRawDataAsMonochrome = false)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

string filename

Path of the image file

bool storeBayerRawDataAsMonochrome

If true, and the image buffer's pixel format is a bayer format, interpret the pixel data as monochrome and store the raw data as a monochrome image.

Remarks

Depending on the pixel format of the image buffer, a transformation is applied before saving the image:

  • Monochrome pixel formats are converted to Mono8 and stored as a 8-bit monochrome bitmap file.
  • Bayer, RGB and YUV pixel formats are converted to BGR8 and stored as a 24-bit color bitmap file.
Exceptions
Type Condition
ArgumentNullException

buffer is null, or filename is null

IC4Exception

Check ErrorCode and ToString() for details.

SaveAsJpeg(ImageBuffer, string, int)

Saves an image buffer as a Jpeg file

Declaration
public static void SaveAsJpeg(this ImageBuffer buffer, string filename, int qualityPercent = 75)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

string filename

Path of the image file

int qualityPercent

Specifies the Jpeg image quality in percent.

High quality images will take more disk space, low quality images are smaller.

Remarks

Depending on the pixel format of the image buffer, a transformation is applied before saving the image:

  • Monochrome pixel formats are converted to Mono8 and stored as a monochrome Jpeg file.
  • Bayer, RGB and YUV pixel formats are converted to BGR8 stored as a color Jpeg file.
Exceptions
Type Condition
ArgumentNullException

buffer is null, or filename is null

IC4Exception

Check ErrorCode and ToString() for details.

SaveAsPng(ImageBuffer, string, bool, PngCompressionLevel)

Saves an image buffer as a PNG file.

Declaration
public static void SaveAsPng(this ImageBuffer buffer, string filename, bool storeBayerRawDataAsMonochrome = false, PngCompressionLevel compressionLevel = PngCompressionLevel.Auto)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

string filename

Path of the image file

bool storeBayerRawDataAsMonochrome

If true, and the image buffer's pixel format is a bayer format, interpret the pixel data as monochrome and store the raw data as a monochrome image.

PngCompressionLevel compressionLevel

Specifies the PNG compression level.

Remarks

Depending on the pixel format of the image buffer, a transformation is applied before saving the image:

  • Monochrome pixel formats with a bit depth higher than 8bpp are converted to Mono16 and stored as a monochrome PNG file with 16 bits per channel.
  • Mono8 image buffers are stored as a monochrome PNG file with 8 bits per channel.
  • Bayer format with a bit depth higher than 8bpp are converted to BGRa16 and stored as a 4-channel PNG with 16 bits per channel.
  • 8-bit Bayer, RGB and YUV pixel formats are converted to BGR8 stored as a 3-channel PNG file with 8 bits per channel.
Exceptions
Type Condition
ArgumentNullException

buffer is null, or filename is null

IC4Exception

Check ErrorCode and ToString() for details.

SaveAsTiff(ImageBuffer, string, bool)

Saves an image buffer as a Tiff file.

Declaration
public static void SaveAsTiff(this ImageBuffer buffer, string filename, bool storeBayerRawDataAsMonochrome = false)
Parameters
Type Name Description
ImageBuffer buffer

An image buffer

string filename

Path of the image file

bool storeBayerRawDataAsMonochrome

If true, and the image buffer's pixel format is a bayer format, interpret the pixel data as monochrome and store the raw data as a monochrome image.

Remarks

Depending on the pixel format of the image buffer, a transformation is applied before saving the image:

  • Monochrome pixel formats with a bit depth higher than 8bpp are converted to Mono16 and stored as a monochrome Tiff file with 16 bits per channel.
  • Mono8 image buffers are stored as a monochrome Tiff file with 8 bits per channel.
  • Bayer formats with a bit depth higher than 8bpp are converted to BGRa16 and stored as a 4-channel Tiff file with 16 bits per channel.
  • 8-bit Bayer, RGB and YUV pixel formats are converted to BGR8 stored as a 3-channel Tiff file with 8 bits per channel.
Exceptions
Type Condition
ArgumentNullException

buffer is null, or filename is null

IC4Exception

Check ErrorCode and ToString() for details.