Skip to content

PixelDataConverter Class#

Creates new images by converting a source image to another format.

Inheritance Hierarchy#

System.Object
  Basler.Pylon.PixelDataConverter

Syntax#

C#

public class PixelDataConverter : IDisposable

VB

Public Class PixelDataConverter
    Implements IDisposable

The PixelDataConverter type exposes the following members.

Constructors#

NameDescription
Public methodPixelDataConverter Initializes a new instance of the PixelDataConverter class
 

Properties#

NameDescription
Public propertyOutputPixelFormat Sets or gets the output pixel format.
Public propertyParameters The parameter collection of the camera object.
 

Methods#

NameDescription
Public methodConvert(IntPtr, Int64, IImage) Creates a new image by converting an image to a different format.
Public methodConvert(IntPtr, Int64, IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(T)(T[], IImage) Creates a new image by converting an image to a different format.
Public methodConvert(T)(T[], IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(T)(IntPtr, Int64, T[], PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(T, U)(T[], U[], PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodDispose Releases all resources used by the PixelDataConverter
Public methodGetBufferSizeForConversion(IImage) Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.
Public methodGetBufferSizeForConversion(PixelType, Int32, Int32) Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.
Public methodStatic memberIsSupportedInputFormat Indicates if the given pixel format is a supported input format.
Public methodStatic memberIsSupportedOutputFormat Indicates if the given pixel format is a supported output format.
 

Remarks#

Supported input image formats defined by the pixel type:  

  • Mono1packed
  • Mono2packed
  • Mono4packed
  • Mono8
  • Mono10
  • Mono10packed
  • Mono10p
  • Mono12
  • Mono12packed
  • Mono12p
  • Mono16
   
  • BayerGR8
  • BayerRG8
  • BayerGB8
  • BayerBG8
  • BayerGR10
  • BayerRG10
  • BayerGB10
  • BayerBG10
  • BayerGR12
  • BayerRG12
  • BayerGB12
  • BayerBG12
  • BayerGR12Packed
  • BayerRG12Packed
  • BayerGB12Packed
  • BayerBG12Packed
  • BayerGR12p
  • BayerRG12p
  • BayerGB12p
  • BayerBG12p
  • BayerGR16
  • BayerRG16
  • BayerGB16
  • BayerBG16
   
  • RGB8packed
  • BGR8packed
  • RGBA8packed
  • BGRA8packed
  • GB10packed
  • BGR10packed
  • RGB12packed
  • BGR12packed
  • RGB12V1packed
  • RGB16packed
  • RGB8planar
  • RGB16planar
   
  • YUV422packed
  • YUV422_YUYV_Packed
  Supported output image formats defined by the pixel type:  
  • BGRA8packed - This pixel type can be used in Windows bitmaps.
  • BGR8packed - This pixel type can be used in Windows bitmaps.
  • RGB8packed
  • RGB16packed
  • RGB8planar
  • RGB16planar
  • Mono8
  • Mono16
  All input image formats can be converted to all output image formats.

RGB, BGR and Bayer image formats are converted to monochrome formats by using the following formula: C++

mono = (0.25 * red) + (0.625 * green) + (0.125 * blue);
YUV formats are converted to 16 bit bit depth in an intermediate conversion step. This is why the output is always aligned at the most significant bit when converting to 16 bit color output formats like RGB16packed.

Limitations: The last column of an YUV input image with odd width cannot be converted. The last column and the last row of a Bayer input image cannot be converted. The default treatment of rows and columns that cannot be converted due to their location on edges can be controlled using the @PixelDataConverter/InconvertibleEdgeHandling parameter. For more information, see the Convert() method description.

Thread Safety: The PixelDataConverter class is not thread-safe.

PixelDataConverter.Convert Method (IntPtr, Int64, IImage)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert(
    IntPtr pDestinationBuffer,
    long destinationBufferSizeBytes,
    IImage sourceImage
)

VB

Public Overridable Sub Convert ( 
    pDestinationBuffer As IntPtr,
    destinationBufferSizeBytes As Long,
    sourceImage As IImage
)

Parameters#

 

pDestinationBuffer
Type: System.IntPtr
The pointer to the buffer of the destination image.
destinationBufferSizeBytes
Type: System.Int64
The size of the buffer of the destination image.
sourceImage
Type: Basler.Pylon.IImage
The source image.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Convert Method (IntPtr, Int64, IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert(
    IntPtr pDestinationBuffer,
    long destinationBufferSizeBytes,
    IntPtr pSourceBuffer,
    long sourceBufferSizeBytes,
    PixelType sourcePixelType,
    int sourceWidth,
    int sourceHeight,
    int sourcePaddingX,
    ImageOrientation sourceOrientation
)

VB

Public Overridable Sub Convert ( 
    pDestinationBuffer As IntPtr,
    destinationBufferSizeBytes As Long,
    pSourceBuffer As IntPtr,
    sourceBufferSizeBytes As Long,
    sourcePixelType As PixelType,
    sourceWidth As Integer,
    sourceHeight As Integer,
    sourcePaddingX As Integer,
    sourceOrientation As ImageOrientation
)

Parameters#

 

pDestinationBuffer
Type: System.IntPtr
The pointer to the buffer of the destination image.
destinationBufferSizeBytes
Type: System.Int64
The size of the buffer of the destination image.
pSourceBuffer
Type: System.IntPtr
The pointer to the buffer of the source image.
sourceBufferSizeBytes
Type: System.Int64
The size of the buffer of the source image.
sourcePixelType
Type: Basler.Pylon.PixelType
The pixel type of the source image.
sourceWidth
Type: System.Int32
The number of pixels in a row in the source image.
sourceHeight
Type: System.Int32
The number of rows in the source image.
sourcePaddingX
Type: System.Int32
The number of extra data bytes at the end of each row. The default value is usually 0.
sourceOrientation
Type: Basler.Pylon.ImageOrientation
The vertical orientation of the source image in the image buffer. The default value is usually ImageOrientation.TopDown.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The source buffer parameters must point to a valid image.
  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  • The sourceWidth value must be >= 0.
  • The sourceHeight value must be >= 0.
  • The sourcePaddingX value must be >= 0.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Convert(T) Method (IntPtr, Int64, T[], PixelType, Int32, Int32, Int32, ImageOrientation)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert<T>(
    IntPtr pDestinationBuffer,
    long destinationBufferSizeBytes,
    T[] sourceBuffer,
    PixelType sourcePixelType,
    int sourceWidth,
    int sourceHeight,
    int sourcePaddingX,
    ImageOrientation sourceOrientation
)

VB

Public Overridable Sub Convert(Of T) ( 
    pDestinationBuffer As IntPtr,
    destinationBufferSizeBytes As Long,
    sourceBuffer As T(),
    sourcePixelType As PixelType,
    sourceWidth As Integer,
    sourceHeight As Integer,
    sourcePaddingX As Integer,
    sourceOrientation As ImageOrientation
)

Parameters#

 

pDestinationBuffer
Type: System.IntPtr
The pointer to the buffer of the destination image.
destinationBufferSizeBytes
Type: System.Int64
The size of the buffer of the destination image.
sourceBuffer
Type: T[]
The array providing the buffer of the source image.
sourcePixelType
Type: Basler.Pylon.PixelType
The pixel type of the source image.
sourceWidth
Type: System.Int32
The number of pixels in a row in the source image.
sourceHeight
Type: System.Int32
The number of rows in the source image.
sourcePaddingX
Type: System.Int32
The number of extra data bytes at the end of each row. The default value is usually 0.
sourceOrientation
Type: Basler.Pylon.ImageOrientation
The vertical orientation of the source image in the image buffer. The default value is usually ImageOrientation.TopDown.

Type Parameters#

 

T
The array item value type of the source buffer array.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The source buffer parameters must point to a valid image.
  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  • The sourceWidth value must be >= 0.
  • The sourceHeight value must be >= 0.
  • The sourcePaddingX value must be >= 0.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Convert(T) Method (T[], IImage)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert<T>(
    T[] destinationBuffer,
    IImage sourceImage
)

VB

Public Overridable Sub Convert(Of T) ( 
    destinationBuffer As T(),
    sourceImage As IImage
)

Parameters#

 

destinationBuffer
Type: T[]
The array providing the buffer of the destination image.
sourceImage
Type: Basler.Pylon.IImage
The source image.

Type Parameters#

 

T
The array item value type of the destination buffer array.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Convert(T) Method (T[], IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert<T>(
    T[] destinationBuffer,
    IntPtr pSourceBuffer,
    long sourceBufferSizeBytes,
    PixelType sourcePixelType,
    int sourceWidth,
    int sourceHeight,
    int sourcePaddingX,
    ImageOrientation sourceOrientation
)

VB

Public Overridable Sub Convert(Of T) ( 
    destinationBuffer As T(),
    pSourceBuffer As IntPtr,
    sourceBufferSizeBytes As Long,
    sourcePixelType As PixelType,
    sourceWidth As Integer,
    sourceHeight As Integer,
    sourcePaddingX As Integer,
    sourceOrientation As ImageOrientation
)

Parameters#

 

destinationBuffer
Type: T[]
The array providing the buffer of the destination image.
pSourceBuffer
Type: System.IntPtr
The pointer to the buffer of the source image.
sourceBufferSizeBytes
Type: System.Int64
The size of the buffer of the source image.
sourcePixelType
Type: Basler.Pylon.PixelType
The pixel type of the source image.
sourceWidth
Type: System.Int32
The number of pixels in a row in the source image.
sourceHeight
Type: System.Int32
The number of rows in the source image.
sourcePaddingX
Type: System.Int32
The number of extra data bytes at the end of each row. The default value is usually 0.
sourceOrientation
Type: Basler.Pylon.ImageOrientation
The vertical orientation of the source image in the image buffer. The default value is usually ImageOrientation.TopDown.

Type Parameters#

 

T
The array item value type of the destination buffer array.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The source buffer parameters must point to a valid image.
  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  • The sourceWidth value must be >= 0.
  • The sourceHeight value must be >= 0.
  • The sourcePaddingX value must be >= 0.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Convert(T, U) Method (T[], U[], PixelType, Int32, Int32, Int32, ImageOrientation)#

Creates a new image by converting an image to a different format.

Syntax#

C#

public virtual void Convert<T, U>(
    T[] destinationBuffer,
    U[] sourceBuffer,
    PixelType sourcePixelType,
    int sourceWidth,
    int sourceHeight,
    int sourcePaddingX,
    ImageOrientation sourceOrientation
)

VB

Public Overridable Sub Convert(Of T, U) ( 
    destinationBuffer As T(),
    sourceBuffer As U(),
    sourcePixelType As PixelType,
    sourceWidth As Integer,
    sourceHeight As Integer,
    sourcePaddingX As Integer,
    sourceOrientation As ImageOrientation
)

Parameters#

 

destinationBuffer
Type: T[]
The array providing the buffer of the destination image.
sourceBuffer
Type: U[]
The array providing the buffer of the source image.
sourcePixelType
Type: Basler.Pylon.PixelType
The pixel type of the source image.
sourceWidth
Type: System.Int32
The number of pixels in a row in the source image.
sourceHeight
Type: System.Int32
The number of rows in the source image.
sourcePaddingX
Type: System.Int32
The number of extra data bytes at the end of each row. The default value is usually 0.
sourceOrientation
Type: Basler.Pylon.ImageOrientation
The vertical orientation of the source image in the image buffer. The default value is usually ImageOrientation.TopDown.

Type Parameters#

 

T
The array item value type of the destination buffer array.
U
The array item value type of the source buffer array.

Remarks#

The image is converted to the destination image according to the current converter settings. The padding area of a row in the destination image is set to zero.

Preconditions:
 

  • The source buffer parameters must point to a valid image.
  • The format of the source image must be supported by the converter.
  • The destination image buffer must be large enough to hold the destination image.
  • The source image buffer and the destination image buffer must not be identical.
  • The sourceWidth value must be >= 0.
  • The sourceHeight value must be >= 0.
  • The sourcePaddingX value must be >= 0.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the passed parameters are not valid. The converter object is still valid after an error.

PixelDataConverter.Dispose Method#

Releases all resources used by the PixelDataConverter

Syntax#

C#

public void Dispose()

VB

Public Sub Dispose

Implements#

IDisposable.Dispose()

PixelDataConverter.GetBufferSizeForConversion Method (IImage)#

Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.

Syntax#

C#

public virtual long GetBufferSizeForConversion(
    IImage sourceImage
)

VB

Public Overridable Function GetBufferSizeForConversion ( 
    sourceImage As IImage
) As Long

Parameters#

 

sourceImage
Type: Basler.Pylon.IImage
The source image.

Return Value#

Type: Int64
The size of the destination image when converting the given source image using current converter settings. Use ToInt32(Int64) to convert to 32 bit if necessary.

Remarks#

Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the destination image size for the input cannot be computed. The converter object is still valid after an error.

PixelDataConverter.GetBufferSizeForConversion Method (PixelType, Int32, Int32)#

Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.

Syntax#

C#

public virtual long GetBufferSizeForConversion(
    PixelType sourcePixelType,
    int sourceWidth,
    int sourceHeight
)

VB

Public Overridable Function GetBufferSizeForConversion ( 
    sourcePixelType As PixelType,
    sourceWidth As Integer,
    sourceHeight As Integer
) As Long

Parameters#

 

sourcePixelType
Type: Basler.Pylon.PixelType
The pixel type of the source image.
sourceWidth
Type: System.Int32
The number of pixels in a row in the source image.
sourceHeight
Type: System.Int32
The number of rows in the source image.

Return Value#

Type: Int64
The size of the destination image when converting the source image using current converter settings. Use ToInt32(Int64) to convert to 32 bit if necessary.

Remarks#

Preconditions:
 

  • The sourceWidth value must be >= 0.
  • The sourceHeight value must be >= 0.
  Thread Safety: This method is not thread-safe.

Error Safety: Throws an exception if the destination image size for the input cannot be computed. The converter object is still valid after an error.

PixelDataConverter.IsSupportedInputFormat Method#

Indicates if the given pixel format is a supported input format.

Syntax#

C#

public static bool IsSupportedInputFormat(
    PixelType sourcePixelType
)

VB

Public Shared Function IsSupportedInputFormat ( 
    sourcePixelType As PixelType
) As Boolean

Parameters#

 

sourcePixelType
Type: Basler.Pylon.PixelType
The pixel format of the source image.

Return Value#

Type: Boolean
Returns true if the given pixel format is supported.

Remarks#

Thread Safety: This method is not thread-safe.

Error Safety: Does not throw C++ exceptions.

PixelDataConverter.IsSupportedOutputFormat Method#

Indicates if the given pixel format is a supported output format.

Syntax#

C#

public static bool IsSupportedOutputFormat(
    PixelType destinationPixelType
)

VB

Public Shared Function IsSupportedOutputFormat ( 
    destinationPixelType As PixelType
) As Boolean

Parameters#

 

destinationPixelType
Type: Basler.Pylon.PixelType
The pixel format of the destination image.

Return Value#

Type: Boolean
Returns true if the given pixel format is supported.

Remarks#

Thread Safety: This method is not thread-safe.

Error Safety: Does not throw C++ exceptions.

PixelDataConverter Constructor#

Initializes a new instance of the PixelDataConverter class

Syntax#

C#

public PixelDataConverter()

VB

Public Sub New

PixelDataConverter.Convert Method#

Overload List#

NameDescription
Public methodConvert(T)(T[], IImage) Creates a new image by converting an image to a different format.
Public methodConvert(IntPtr, Int64, IImage) Creates a new image by converting an image to a different format.
Public methodConvert(T, U)(T[], U[], PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(T)(T[], IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(T)(IntPtr, Int64, T[], PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
Public methodConvert(IntPtr, Int64, IntPtr, Int64, PixelType, Int32, Int32, Int32, ImageOrientation) Creates a new image by converting an image to a different format.
 

PixelDataConverter.GetBufferSizeForConversion Method#

Overload List#

NameDescription
Public methodGetBufferSizeForConversion(IImage) Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.
Public methodGetBufferSizeForConversion(PixelType, Int32, Int32) Computes the size of the destination image buffer in byte. Use ToInt32(Int64) to convert to 32 bit if necessary.
 

PixelDataConverter.OutputPixelFormat Property#

Sets or gets the output pixel format.

Syntax#

C#

public virtual PixelType OutputPixelFormat { get; set; }

VB

Public Overridable Property OutputPixelFormat As PixelType
    Get
    Set

Property Value#

Type: PixelType

Remarks#

Thread Safety: This property is not thread-safe.

Error Safety: Throws an exception if OutputPixelFormat is set to an unsupported or invalid PixelFormat. The converter object is still valid after an error.

PixelDataConverter.Parameters Property#

The parameter collection of the camera object.

Syntax#

C#

public virtual IParameterCollection Parameters { get; }

VB

Public Overridable ReadOnly Property Parameters As IParameterCollection
    Get

Return Value#

Type: IParameterCollection
Returns the parameter collection of the camera object.

Remarks#

You can access parameters by passing a key from a parameter list to the index operator, e.g. key from a parameter list, e.g. C++

camera.Parameters[PLFormatConverter.OutputPaddingX].GetValue();

Thread Safety: This method is thread-safe.

Error Safety: Does not throw exceptions.