Available in the LEADTOOLS Imaging toolkit. |
FeedLoad example for Visual J++
This example uses StartFeedLoad, FeedLoad, and StopFeedLoad and loads a file through a buffer to simulate receiving a transmitted image.
private void FeedLoad_click(Object source, Event e)
{
// Open an image file and get its length.
File file = new File( "c:\\lead\\images\\image1.cmp", FileMode.OPEN, FileAccess.READ, FileShare.READ );
int nFileLength = (int) file.getLength();
// Set PaintWhileLoad so that we can watch the progress.
LEAD1.setPaintWhileLoad( true );
// Initialize the file-load process.
// Specify the default bits per pixel and first page
if( LEAD1.StartFeedLoad( (short) 0, (short) 0, (short) 1 ) != 0 )
{
MessageBox.show( "Error in StartFeedLoad !" );
file.close();
return;
}
// set the buffer size
final int BUFFERSIZE = 1000;
// Use FeedLoad in a loop to load the file into the bitmap.
int nSizeLeft = nFileLength;
while( nSizeLeft > 0 )
{
// get size
int nReadSize = (int) Math.min( nSizeLeft, BUFFERSIZE );
nSizeLeft -= nReadSize;
// read from file
byte byBuffer[] = file.readBytes( nReadSize );
// set into a safe array
SafeArray aMyArray = new SafeArray( Variant.VariantByte, BUFFERSIZE );
aMyArray.setBytes( 0, nReadSize, byBuffer, 0 );
// feed load
if( LEAD1.FeedLoad( new Variant( aMyArray, false ), nReadSize ) != 0 )
{
MessageBox.show( "Error in FeedLoad !");
file.close();
return;
}
}
// Finish the file-load process.
if( LEAD1.StopFeedLoad() != 0 )
{
MessageBox.show( "Error in StopFeedLoad !" );
file.close();
return;
}
file.close();
}