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 = static_smart_ptr_cast<FrameHandlerSink>( 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.
    saveToFileBMP( *pSink->getLastAcqMemBuffer(), "image.bmp" );
}

See also: FrameHandlerSink, FrameHandlerSink::snapImagesAsync

<< FrameHandlerSink