Skip to main content

MgraAlloc

BoardSupported
Host SystemYes
V4L2Yes
Clarity UHDYes
Concord PoENo
GenTLYes
GevIQYes
GigE VisionYes
IndioNo
Iris GTXYes
Radient eV-CLYes
Rapixo CLYes
Rapixo CoFYes
Rapixo CXPYes
USB3 VisionYes

Allocate a 2D graphics context.

Syntax

AIL_ID MgraAlloc(
AIL_ID SysId, //in
AIL_ID * ContextGraIdPtr //out
)

Description

This function allocates a 2D graphics context on the specified system. A 2D graphics context is required to use Aurora Imaging Library graphics to perform annotations. Whenever an annotation is done, 2D graphics context settings are inherited by the graphics. Different contexts can coexist; use their identifier to specify which to use or change.

To modify or inquire 2D graphics context settings, use MgraControl and MgraInquire.

Note that, upon allocation of an application, a default 2D graphics context is automatically allocated. Rather than using MgraAlloc to allocate a 2D graphics context, you can use this default 2D graphics context, by specifying M_DEFAULT wherever a 2D graphics context identifier is required. Note that there is a different default 2D graphics context for each thread.

When the 2D graphics context is no longer required, release it usingMgraFreeunless M_UNIQUE_ID was specified during allocation; if M_UNIQUE_ID was specified, the smart identifier manages the 2D graphics context's lifetime and you must not manually free it.

Parameters

SysId (in, AIL_ID)

Specifies the system on which to allocate the 2D graphics context.

For specifying the system

ValueDescription
M_DEFAULT_HOSTSpecifies the default Host system of the current Aurora Imaging Library application.
System identifierSpecifies a valid system identifier, previously allocated using MsysAlloc.

ContextGraIdPtr *(out, AIL_ID)

Specifies the address of the variable in which to write the 2D graphics context identifier or specifies the data type that the function should use to return the 2D graphics context identifier.

For retrieving the identifier or specifying how to return it

ValueDescription
M_NULLSpecifies that you will use this function's return value to obtain the identifier of the allocated 2D graphics context; in this case, a standard Aurora Imaging Library identifier of type AIL_ID is returned.
M_UNIQUE_IDSpecifies that you will use this function's return value to obtain the identifier of the allocated 2D graphics context; in this case, an Aurora Imaging Library smart identifier of type _AIL_UNIQUE_GRA_ID_is returned instead of a standard Aurora Imaging Library identifier.This setting is only available when using C++11 (or later).An Aurora Imaging Library smart identifier manages the lifespan of the Aurora Imaging Library object it owns (similar to a std::unique_ptr). Note, you can use an Aurora Imaging Library smart identifier as though it were a standard Aurora Imaging Library identifier, except that you cannot use it to manually free the 2D graphics context (it is freed automatically). For more information, see Aurora Imaging Library smart identifiers.
Address in which to write the identifierSpecifies the address of an AIL_ID in which to write the identifier of the allocated 2D graphics context.

If allocation fails, M_NULL is written as the identifier. |

Return Value

Type: AIL_ID

The returned value is the 2D graphics context identifier either as a standard identifier (AIL_ID) or a smart identifier (AIL_UNIQUE_GRA_ID). If allocation fails, M_NULL is returned (or nullptr ifM_UNIQUE_ID was specified).

Copyright © 2026 Zebra Technologies.