Memory Allocation

You can construct an image using an internal or an external memory allocation.

Internal memory allocation

The image object dynamically allocates and deallocates a buffer:

  • The memory management is transparent.

  • When the image size changes, a reallocation occurs.

  • When an image object is destroyed, the buffer is deallocated.

To declare an image with an internal memory allocation:

  1. Construct an image object, for instance EImageBW8 .NET Python, either with width and height arguments or using the EBaseROI::SetSize .NET Python function.

  2. Access a given pixel using one of the multiple available functions.
    For example, use EBaseROI::GetImagePtr .NET Python to retrieve a pointer to the first byte of the pixel at the given coordinates.

External memory allocation

Control the buffer allocation or link a third-party image in the memory buffer to an eVision image.

  • You must specify the image size and the buffer address.

  • When an image object is destroyed, the buffer is unaffected.

To declare an image with an external memory allocation:

  1. Declare an image object, for instance EImageBW8 .NET Python.

  2. Create a suitably sized and aligned buffer.

  3. Assign the buffer to the image with EBaseROI::SetImagePtr .NET Python.

Note

Using the copy constructor of the EImage object to copy the externally allocated image does not copy the buffer.
The copied image points to the same external buffer as the original image.

Note

If your buffer rows are not aligned on 4 bytes, use EImageBW8::InitializeFromUnalignedBuffer .NET Python instead of EBaseROI::SetImagePtr .NET Python.
Please note that this allocates the memory internally and copies the external buffer into the internal one instead of using the external one.