Available in the LEADTOOLS Imaging toolkit. |
AutoAnimate Example for Visual J++
This example gets information about an animated file, uses the information to position the LEAD control, and plays the animation as it loads the file.
// Force continued looping after the file loads.
LEAD1.setAutoAnimationLoop( (short) LTOCXU.AutoAnimationLoopConstants.AUTOANIMATIONLOOP_INFINITE );
// Get information about the file we will load.
LEAD1.GetFileInfo( "c:\\lead\\images\\sample1.avi", (short) 0, 0 );
// Exit if this is not an animated file.
if( !LEAD1.getInfoAnimation() )
MessageBox.show( "Not an animated file", "Error", MessageBox.OK );
else
{
// Calculate information for centering the LEAD control.
// Set the variables used for preserving the aspect ratio.
// Allow for a border of 1/8 of the form size.
// The units of measure do not matter, since we are calculating proportions.
int nHeightFactor = (int) LEAD1.getInfoHeight();
int nWidthFactor = (int) LEAD1.getInfoWidth();
int nHeightAllowed = getWidth() * 3 / 4;
int nWidthAllowed = getHeight() * 3 / 4;
// Center the LEAD control on the form, preserving the aspect ratio.
// Check to see if using the maximum width will make the image too tall.
// Set the dimensions based on the result.
Rectangle rectLead = new Rectangle();
if( ( ( nWidthAllowed * nHeightFactor ) / nWidthFactor ) < nHeightAllowed )
{
rectLead.x = getWidth() / 8;
rectLead.width = nWidthAllowed;
rectLead.height = ( LEAD1.getWidth() * nHeightFactor ) / nWidthFactor;
rectLead.y = ( getHeight() - LEAD1.getHeight() ) / 2;
}
else
{
rectLead.y = getHeight() / 8;
rectLead.height = nHeightAllowed;
rectLead.width = ( LEAD1.getHeight() * nWidthFactor ) / nHeightFactor;
rectLead.x = ( getWidth() - LEAD1.getWidth() ) / 2;
}
LEAD1.setLocation( rectLead.x, rectLead.y );
LEAD1.setSize( rectLead.width, rectLead.height );
// Set properties for playing the animation as is loads.
LEAD1.setAutoAnimate( true );
LEAD1.setAutoRepaint( true );
// Load the animated file.
LEAD1.Load( "c:\\lead\\images\\sample1.avi", (short) 0, (short) 0, (short) -1 );
}