• Introduction
  • Programmer's Guide
  • Technical Articles
  • API Documentation
Search Results for

    Show / Hide Table of Contents
    • ic4
      • BufferPool
      • DeviceEnum
      • DeviceInfo
      • Display
      • DisplayNotation
      • DisplayRenderPosition
      • DisplayStatistics
      • DisplayType
      • EmbeddedDisplay
      • ErrorCode
      • ExternalOpenGLDisplay
      • FloatRepresentation
      • FloatingDisplay
      • FrameMetaData
      • Grabber
      • HandleObject
      • IBufferAllocator
      • IC4Exception
      • IDisplay
      • ImageBuffer
      • ImageBuffer.CopyOptions
      • ImageBufferExtensions
      • ImageBufferExtensionsHalconDotNet
      • ImageBufferExtensionsOpenCvSharp
      • ImageBufferExtensionsSystemDrawing
      • ImageBufferExtensionsSystemWindowsMedia
      • ImageType
      • IntRepresentation
      • Interface
      • Library
      • LogLevel
      • LogTarget
      • PixelFormat
      • PixelFormatExtensions
      • PngCompressionLevel
      • PropBoolean
      • PropCategory
      • PropCommand
      • PropEnumEntry
      • PropEnumeration
      • PropFloat
      • PropId
      • PropIdBoolean
      • PropIdCommand
      • PropIdEnumeration
      • PropIdFloat
      • PropIdInteger
      • PropIdRegister
      • PropIdString
      • PropInteger
      • PropRegister
      • PropString
      • Property
      • PropertyIncrementMode
      • PropertyMap
      • PropertyType
      • PropertyVisibility
      • QueueSink
      • QueueSinkConnectedEventArgs
      • QueueSinkEventArgs
      • QueueSinkQueueSizes
      • Sink
      • SinkMode
      • SinkType
      • SnapSink
      • SnapSinkAllocationStrategy
      • StreamSetupOption
      • StreamStatistics
      • TransportLayerType
      • VersionInfoFlags
      • VideoWriter
      • VideoWriterType
    • ic4.WinForms
      • Dialogs
      • Display
      • PropertyDialogFlags

    Class ImageBufferExtensionsHalconDotNet

    Contains extension methods for ImageBuffer for interop with the MVTec.HalconDotNet library (https://mvtec.com/).

    Inheritance
    object
    ImageBufferExtensionsHalconDotNet
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: ic4
    Assembly: ic4dotnet.HalconDotNet.dll
    Syntax
    public static class ImageBufferExtensionsHalconDotNet
    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 HImage object HImage img = imageBuffer.CreateHImageCopy();

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

    // Get image buffer from somewhere
    ImageBuffer imageBuffer = GetImageBuffer();
    // Create copy in a HImage object
    HImage img = ImageBufferExtensionsHalconDotNet.CreateHImageCopy(imageBuffer);

    Methods

    CopyFrom(ImageBuffer, HImage)

    Copies the contents of a HALCON HImage into this ImageBuffer.

    Declaration
    public static void CopyFrom(this ImageBuffer buffer, HImage src)
    Parameters
    Type Name Description
    ImageBuffer buffer

    An image buffer

    HImage src

    An Halcon HImage

    Remarks

    The image type of buffer needs to match the dimensions and type of src.

    • If src is a 1-channel image of type byte, buffer must be Mono8 of the same size.
    • If src is a 1-channel image of type uint2, buffer must be Mono16 of the same size.
    • If src is a 3-channel image of type byte, buffer must be BGRa8 of the same size.
    • If src is a 3-channel image of type uint2, buffer must be BGRa16 of the same size.
    • Other image types are not supported.
    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null or src is null.

    NotSupportedException

    The type of src is not supported.

    ArgumentException

    T image type of buffer does not match the type and dimensions of src.

    CreateHImageCopy(ImageBuffer)

    Creates a copy of the image buffer's data and stores it in a HImage.

    Declaration
    public static HImage CreateHImageCopy(this ImageBuffer buffer)
    Parameters
    Type Name Description
    ImageBuffer buffer

    An image buffer

    Returns
    Type Description
    HImage

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

    Remarks

    The image format of the `HImage` depends on the pixel format of the image buffer:

    • Mono8 image buffers are returned in a single-channel byte image.
    • Monochrome image buffers with more than 8 bits per pixel (e.g. Mono12p) are converted and returned in a single-channel uint2 image.
    • 8-bit Bayer image buffers (e.g. BayerBG8) are converted to a 3-channel byte image.
    • Bayer image buffers with more than 8 bits per pixel (e.g. BayerGB12p) are converted to a 3-channel uint2 image.
    • BGRa16 image buffers are returned as a 3-channel uint2 image.
    • Any other color image buffer (e.g. BGRa8) are returned in a 3-channel byte image.
    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null

    NotSupportedException

    The pixel format of the image buffer is not supported.

    CreateHImageWrap(ImageBuffer)

    Wraps the passed image buffer in a HImage.

    Declaration
    public static HImage CreateHImageWrap(this ImageBuffer buffer)
    Parameters
    Type Name Description
    ImageBuffer buffer

    An image buffer

    Returns
    Type Description
    HImage

    A HImage using the image buffer's memory as pixel storage

    Remarks

    Check IsHImageWrapSupported(ImageBuffer) to find out whether wrapping the image buffer is possible.

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

    • Mono8
    • Mono16

    There must not be any horizontal padding in the image buffer. Pitch must be equal to the image's width times the bytes per pixel of the image's pixel format.

    The returned HImage objects maintains a reference to the passed image buffer, preventing it from being reused until the HImage object is disposed (or garbage collected).

    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null

    NotSupportedException

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

    CreateImageBufferCopy(HImage)

    Copies the contents of an HALCON HImage into a new ImageBuffer.

    Declaration
    public static ImageBuffer CreateImageBufferCopy(this HImage src)
    Parameters
    Type Name Description
    HImage src

    An HALCON HImage

    Returns
    Type Description
    ImageBuffer

    A new image buffer containing a copy of the contents of src.

    Remarks

    The resulting image buffer's pixel format depends on the type of src:

    • If src is a 1-channel image of type byte, the pixel format for the returned image buffer is Mono8.
    • If src is a 1-channel image of type uint2, the pixel format for the returned image buffer is Mono16.
    • If src is a 3-channel image of type byte, the pixel format for the returned image buffer is BGRa8.
    • If src is a 3-channel image of type uint2, the pixel format for the returned image buffer is BGRa16.
    • Other image types are not supported.
    Exceptions
    Type Condition
    ArgumentNullException

    src is null

    NotSupportedException

    The type of the HImage is not supported.

    CreateImageBufferCopy(HImage, BufferPool)

    Copies the contents of an HALCON HImage into a new ImageBuffer.

    Declaration
    public static ImageBuffer CreateImageBufferCopy(this HImage src, BufferPool pool)
    Parameters
    Type Name Description
    HImage src

    An HALCON HImage

    BufferPool pool

    A buffer pool to query the new image buffer from

    Returns
    Type Description
    ImageBuffer

    A new image buffer containing a copy of the contents of src.

    Remarks

    The resulting image buffer's pixel format depends on the type of src:

    • If src is a 1-channel image of type byte, the pixel format for the returned image buffer is Mono8.
    • If src is a 1-channel image of type uint2, the pixel format for the returned image buffer is Mono16.
    • If src is a 3-channel image of type byte, the pixel format for the returned image buffer is BGRa8.
    • If src is a 3-channel image of type uint2, the pixel format for the returned image buffer is BGRa16.
    • Other image types are not supported.
    Exceptions
    Type Condition
    ArgumentNullException

    src is null or pool is null.

    NotSupportedException

    The type of the HImage is not supported.

    IsHImageWrapSupported(ImageBuffer)

    Checks whether CreateHImageWrap(ImageBuffer) can be used with the passed image buffer.

    Declaration
    public static bool IsHImageWrapSupported(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 HImage, otherwise false.

    Remarks

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

    • Mono8
    • Mono16

    There must not be any horizontal padding in the image buffer. Pitch must be equal to the image's width times the bytes per pixel of the image's pixel format.

    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null

    In this article
    Copyright ©️ 2024 The Imaging Source Europe GmbH www.theimagingsource.com