IC Imaging Control C++

FrameHandlerSink::snapImages Method

FrameHandlerSink::snapImages Method

Queues up a snap job, thus allowing a number of frames to be copied into the MemBufferCollection. The method returns when either the specified number of frames are snapped, or the timeout has occurred.
Syntax:
Error snapImages( unsigned int count, DWORD timeout = INFINITE );
Parameter Description
count

Number of frames to copy into the MemBufferCollection.

timeout

Number of milliseconds to wait before returning from this function, should no frames be available from the device.

Return Value:

An error object reporting the status of the performed operation. Use Error::isError to check whether the operation was successful.

Remarks:

If the method runs into a timeout, it is not guaranteed, that count frames are snapped. In the case of a timeout, it is possible that by the time this method has returned, GrabberListener::frameReady has already been called.

If live mode has not been started, this method starts live mode before grabbing the image and stops live mode afterward. Because starting live mode is a very time-consuming operation, it is usually preferable to start live mode before calling snapImage more than once.

Example:

The following example shows how to snap an image and save it to a bitmap file. It assumes that a FrameHandlerSink, containing a MemBufferCollection has been setup using FrameHandlerSink::create and assigned to the grabber with Grabber::setSinkType.

// This cast is only valid, if we have previously assigned a FrameHandlerSink to the grabber.
tFrameHandlerSinkPtr pSink = m_Grabber.getSinkTypePtr();
 
// Snap one image and copy it into the MemBufferCollection.
Error e = pSink->snapImages( 1 );
if( e.isError() )
{
    // Display an error.
    ::MessageBoxA( 0, e.toString().c_str(), "Error", MB_OK|MB_ICONERROR );
}
else
{
    // Save the image to a bitmap file.
    pSink->getLastAcqMemBuffer()->save( "image.bmp" );
}
See also: FrameHandlerSink, FrameHandlerSink::snapImagesAsync

<< FrameHandlerSink

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us