Drawing in Images

Introduction

  • Whenever relevant, the eVision tools provide methods Draw to render their contents and/or configuration. This is, for instance, the contents of an EImage or the frame of an EROI.

  • A given tool can have multiple methods Draw, usually one for each feature available.

  • The methods Draw take an object DrawAdapter as their main parameter, and additional parameters for zoom and pan:

    Tool.Draw(EDrawAdapter* adapter, float zoomX, float zoomY, float panX, float panY);

    • zoomX and zoomY are expressed in percentage, 1 is the default value and means no zoom.

    • It can be different in the horizontal and vertical directions (which can be useful in the case of non-square pixels for instance).

    • If you don’t provide a vertical zoom, or set it to 0, it will be set identical to the horizontal one.

    • panX and panY are expressed in pixels, but in image coordinates. It means that the value you pass to panX and panY are multiplied by the corresponding zoom before being applied.

Example: How to draw an image and a ROI frame on a window under Windows:

EImageBW8 image;
EROIBW8 roi;
EWindowsDrawAdapter adapter(windowHdc);
image.Draw(adapter);
roi.DrawFrame(adapter);

Graphical interactions

  • You can configure some of the eVision tools graphically and use the provided methods to put your configuration in place.

  • Graphical Interaction-enabled tools provide special parameters to some of their methods Draw to draw handles on the tool representation.

  • To capture the user interactions with those handles, these tools also provide two specialized methods:

    • HitTest detects if a handle is under the mouse when providing it with the current cursor coordinates. You typically use this test during a mouse button down event.

    • Drag moves the detected handle to the given coordinates. This in turn modifies the tool configuration to match the new handle position. Drag is typically associated with the mouse button up event.

    Note

    HitTest and Drag use the same zoom and pan parameters as Draw. You must set them the same way (with the same values) to achieve the desired result.

  • Use Easy::GetHandleSize .NET Python to change the handle size.

    • This value influences the drawing and the hit area.

    • By default, the handle size is equal to 8 pixels.

Draw adapters

Standard draw adapters

eVision provides a set of off-the-shelf draw adapters that you can use in different situations:

  • EWindowsDrawAdapter .NET Python allows to draw on Windows systems. To draw on a window, provide the window’s HDC to its constructor, or, to draw in an EImage buffer, provide that EImage.

    • It relies on GDI and GDI+ to provide its services.

    • This is the preferred way to draw on Windows.

  • QtDrawAdapter allows you to draw using Qt on a QPainter context. To draw on a QPainter context, provide the QPainter to the constructor, or, to draw on an EImage buffer, provide that EImage.

    • You can use the QtDrawAdapter both on Windows and Linux.

    • This is the preferred way to draw on Linux.

      Note

      QtDrawAdapter is using an external resource (namely Qt) and as such is provided as source code in its own header rather than in the global eVision header. For more information about external and custom draw adapters, see below.

  • EGenericDrawAdapter .NET Python is a draw adapter that can only render on an EImage, but it can do it in a consistent manner on all supported OSes.

    • It is available on both Windows and Linux.

Drawing in an EImage

  • As said above, you can draw in an EImage (usually an EImageBW8 or EImageC24) by initializing a draw adapter with that image and using either the eVision methods Draw or the draw adapter drawing primitives:

EImageBW8 image;
EMatrixCode code;
EWindowsDrawAdapter adapter(image);
code.DrawPosition(adapter);

Custom draw adapters

  • If you require a draw adapter to render in a specific, unsupported type of context (for ex. a DirectDraw surface, an OpenGL context…), you can build your own draw adapter by deriving from the interface EExternalDrawAdapter .NET provided by eVision and implementing all the required methods.

  • Once this work is done, you will be able to use your new, custom draw adapter in the same way as the off-the-shelf ones, taking advantage of eVision methods Draw.

  • The provided QtDrawAdapter is a draw adapter built using that mechanism, you can use it as a reference on how to build a custom draw adapter. The sources of the QtDrawAdapter are bundled with the Qt Samples.

Enhanced Image Display

When the enhanced image display mode is enabled, a high-quality interpolation method is used to display the resized images.

  • Set Easy::SetEnableEnhancedImageDisplay .NET Python to TRUE, to enable the enhanced image display.

  • By default, this option is disabled.

  • Enhanced image display has a significant impact on display speed, the drawing can be 4x to 10x slower.

  • The drawing of images with EBW8Vector or EC24Vector used as Look Up Table doesn’t support enhanced image display

../../../_images/image_drawing_and_overlay_1.webp

EnhancedImageDisplay disabled (left) and enabled (right)

  • eVision Studio exposes this option in View > Option dialog:

../../../_images/image_drawing_and_overlay_2.webp