Available in the LEADTOOLS Imaging toolkit. |
CreateBitmap, Size, and Combine example for Visual J++
This example creates a bitmap for Lead2 (same size and BPS as Lead 1) and fills it with green. It resizes the Lead1 bitmap, then uses a loop to do multiple combines with the Lead2 bitmap. It then copies the Lead2 bitmap to Lead1 and redisplays Lead1.
setCursor( Cursor.WAIT ); // hourglass
// Create the Lead2 bitmap. (The control must already be on the form).
int nMyWidth = (int) LEAD1.getBitmapWidth();
int nMyHeight = (int) LEAD1.getBitmapHeight();
short sMyBPS = LEAD1.getBitmapBits();
LEAD2.CreateBitmap( nMyWidth, nMyHeight, sMyBPS );
LEAD2.Fill( new Color( 0, 255, 0 ) ); // fill with green
// Resize the Lead1 bitmap
int nImageWidth = (int) ( nMyWidth * 0.3f );
int nImageHeight = (int) ( nMyHeight * 0.3f );
LEAD1.Size( nImageWidth, nImageHeight, (short) LTOCXU.ResizeConstants.RESIZE_RESAMPLE );
// Initialize the variables used for multiple combines.
int nTestWidth = nMyWidth; // Used for horizontal positioning
int nTestHeight = nMyHeight; // Used for vertical positioning
int nVFactor = nMyHeight / nImageHeight + 1; // Number spaces between images
int nVSpacing = ( nMyHeight % nImageHeight ) / nVFactor; // Pixels between images
int nHFactor = nMyWidth / nImageWidth + 1; // Number spaces between images
int nHSpacing = ( nMyWidth % nImageWidth ) / nHFactor; // Pixels between images
int nDstT = nVSpacing; // Top coordinate of the destination rectangle
int nSrcL = 0; // Left coordinate of the source rectangle
int nSrcT = 0; // Top coordinate of the source rectangle
int nDstW = nImageWidth; // Width of the destination rectangle
int nDstH = nImageHeight; // Height of the destination rectangle
int nMyOp = LTOCXU.CombineConstants.CB_OP_ADD | LTOCXU.CombineConstants.CB_DST_0; // Operation flags used when combining images
// Do the loop that does the multiple combines
while( nTestHeight > nImageHeight ) // Vertical loop
{
nDstT = nMyHeight - nTestHeight + nVSpacing;
nTestHeight -= nImageHeight - nVSpacing;
while( nTestWidth > nImageWidth ) //Horizontal loop
{
int nDstL = nMyWidth - nTestWidth + nHSpacing;
nTestWidth -= nImageWidth - nHSpacing;
LEAD2.Combine( nDstL, nDstT, nDstW, nDstH, LEAD1.getBitmap(), nSrcL, nSrcT, nMyOp );
}
nTestWidth = nMyWidth;
}
// Copy the Lead2 bitmap to Lead1
LEAD1.setBitmap( LEAD2.getBitmap() );
// Set the image display size to match the LEAD control
LEAD1.SetDstRect( 0, 0, LEAD1.getScaleWidth(), LEAD1.getScaleHeight() );
LEAD1.SetDstClipRect( 0, 0, LEAD1.getScaleWidth(), LEAD1.getScaleHeight() );
LEAD1.ForceRepaint();
setCursor( Cursor.DEFAULT ); // default