Available in the LEADTOOLS Imaging toolkit. |
FeedLoad example for C++ 4.0 and later
This example uses StartFeedLoad, FeedLoad, and StopFeedLoad and loads a file through a buffer to simulate receiving a transmitted image.
#define BUFFERSIZE 1000
void CTutorDlg::OnFeedload()
{
VARIANT variant;
SAFEARRAY *ptrsafearray;
SAFEARRAYBOUND arraybound;
LPSTR lp; /* pointer to the data */
/* Set up the VARIANT and the SAFEARRAY structures */
arraybound.cElements = BUFFERSIZE; /* 1000 bytes at a time */
arraybound.lLbound = 0;
ptrsafearray = SafeArrayCreate( VT_UI1, 1, &arraybound );
SafeArrayLock( ptrsafearray );
lp = (LPSTR)ptrsafearray->pvData; /* get a pointer to the buffer */
V_VT(&variant) = VT_ARRAY | VT_UI1;
V_ARRAY(&variant) = ptrsafearray;
/* Now we have a variant and we can do the real work */
HFILE hf;
int bytesread;
OFSTRUCT of;
if( (hf = OpenFile("v:\\images\\eagle.cmp", &of, OF_READ)) == HFILE_ERROR)
{
SafeArrayUnlock( ptrsafearray );
SafeArrayDestroy( ptrsafearray );
MessageBox( "Error opening file !" );
return;
}
if( m_Lead.StartFeedLoad( 0, 0, 1 ) ) /* default bits per pixel and first page */ {
SafeArrayUnlock( ptrsafearray );
SafeArrayDestroy( ptrsafearray );
_lclose( hf );
MessageBox( "Error in StartFeedLoad !" );
return;
}
do
{
bytesread = (int)_hread( hf, lp, BUFFERSIZE );
if( m_Lead.FeedLoad( variant, bytesread ) )
{
SafeArrayUnlock( ptrsafearray );
SafeArrayDestroy( ptrsafearray );
_lclose( hf );
MessageBox( "Error in FeedLoad !" );
return;
}
} while (bytesread > 0);
if( m_Lead.StopFeedLoad() )
{
SafeArrayUnlock( ptrsafearray );
SafeArrayDestroy( ptrsafearray );
_lclose( hf );
MessageBox( "Error in StopFeedLoad !" );
return;
}
SafeArrayUnlock( ptrsafearray );
SafeArrayDestroy( ptrsafearray );
}