Available in the LEADTOOLS Imaging toolkit. |
GetFloaterHandle example for Visual J++
The following is an alternative way of coding the PasteFloaterBtn button's click event in Outlining, Dragging, and Pasting a Region. This alternative uses the GetFloaterHandle and SetRgnHandle methods to specify the mask for the paste. It also shows how to use the HasRgn, FloaterWidth, and FloaterHeight properties.
// Exit this function if there is no region.
if( !LEAD1.getHasRgn() )
return;
// Save the region that is in the floater.
int hSavedRgn = LEAD1.GetFloaterHandle();
// Get the floater into another bitmap
LEAD2.setScaleMode( LEAD1.getScaleMode() );
LEAD2.setBitmap( LEAD1.getFloater() );
// Get the floater's client coordinates into local variables.
int nLCRgnX = (int) LEAD1.getFloaterDstLeft();
int nLCRgnY = (int) LEAD1.getFloaterDstTop();
int nLCRgnWidth = (int) LEAD1.getFloaterDstWidth();
int nLCRgnHeight = (int) LEAD1.getFloaterDstHeight();
// Translate the client coordinates to bitmap coordinates.
int nZoomFactorX = 1;
int nZoomFactorY = 1;
int nLBRgnX = ( ( nLCRgnX - (int) LEAD1.getDstLeft() ) / nZoomFactorX ) + (int) LEAD1.getSrcLeft();
int nLBRgnY = ( ( nLCRgnY - (int) LEAD1.getDstTop() ) / nZoomFactorY ) + (int) LEAD1.getSrcTop();
int nLBRgnWidth = (int) LEAD1.getFloaterWidth();
int nLBRgnHeight = (int) LEAD1.getFloaterHeight();
// Delete the floater.
LEAD1.setFloaterVisible( false );
LEAD1.setFloater( 0 );
// Set the saved region to use as a mask for the Combine method.
LEAD1.SetRgnHandle( hSavedRgn, nLBRgnX, nLBRgnY, (short) LTOCXU.RgnCombineModeConstants.L_RGN_SET );
// Use the Combine method to paste the Lead2 bitmap into the Lead1 bitmap.
int nMyOp = LTOCXU.CombineConstants.CB_OP_ADD + // Operation flags for a simple paste.
LTOCXU.CombineConstants.CB_DST_0;
LEAD1.Combine( nLBRgnX, nLBRgnY, nLBRgnWidth, nLBRgnHeight, LEAD2.getBitmap(), 0, 0, nMyOp );
// Repaint the part of the client area that has changed.
LEAD1.RepaintRect( nLCRgnX, nLCRgnY, nLCRgnWidth, nLCRgnHeight, false );
// Free the region.
LEAD1.FreeRgn();
// Delete the region handle.
LEAD1.DeleteRgnHandle( hSavedRgn );