Available in the LEADTOOLS Imaging toolkit. |
Using Transparent Controls (Visual J++)
Take the following steps to add transparent controls, with special effects. The transparent controls are added as child controls so that they will scroll with the parent image.
1. Start with the project that you created in Loading and Displaying an Image.
2. Add two LEAD controls, which you will set to be transparent at run time. (At design time, you can make the controls easier to see by setting the BackColor property of each control to a different color.) Add the controls as follows:
a. Add a control named Lead2 as a child control to Lead1. In other words, draw it inside the Lead1 control.
b. Add a control named Lead3 as a child control to Lead2. In other words, draw it inside the Lead2 control.
3. Add a button and code its click event as follows:
private void button1_click(Object source, Event e)
{
LEAD1.setEnableMethodErrors( false );
LEAD1.setAutoRepaint( false );
LEAD2.setAutoRepaint( false );
LEAD3.setAutoRepaint( false );
// Make LEAD2 and LEAD3 transparent.
LEAD2.setTransparent( true );
LEAD3.setTransparent( true );
// Give each control a different effect.
LEAD1.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_WIPE_RECTANGLE_OUT );
LEAD2.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_WIPE_RECTANGLE_IN );
LEAD3.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_ZOOM_FROM_C );
LEAD1.setEffectDelay( (short) 20 );
LEAD2.setEffectDelay( (short) 20 );
LEAD3.setEffectDelay( (short) 20 );
LEAD1.setEffectGrain( (short) 1 );
LEAD2.setEffectGrain( (short) 5 );
LEAD3.setEffectGrain( (short) 1 );
// Position LEAD2 and LEAD3 inside LEAD1.
LEAD2.setWidth( LEAD1.getWidth() / 2 );
LEAD2.setHeight( LEAD1.getHeight() / 2 );
LEAD2.setTop( (LEAD1.getWidth() - LEAD2.getWidth() ) / 2 );
LEAD2.setLeft( (LEAD1.getHeight() - LEAD2.getHeight() ) / 2 );
LEAD3.setTop( 0 );
LEAD3.setLeft( 0 );
LEAD3.setWidth( LEAD2.getWidth() );
LEAD3.setHeight( LEAD2.getHeight() );
// We will be drawing into the bitmaps.
LEAD2.setDrawPersistence( true );
LEAD3.setDrawPersistence( true );
LEAD2.CreateBitmap( LEAD2.getScaleWidth(), LEAD3.getScaleHeight(), (short) 24 );
LEAD3.CreateBitmap( LEAD3.getScaleWidth(), LEAD3.getScaleHeight(), (short) 24 );
// Fill them with black, which we will make transparent.
LEAD2.Fill( new Color( 0, 0, 0 ) );
LEAD3.Fill( new Color( 0, 0, 0 ) );
LEAD2.setBitmapEnableTransparency( true );
LEAD3.setBitmapEnableTransparency( true );
LEAD2.setBitmapTransparentColor( new Color( 0, 0, 0 ) );
LEAD3.setBitmapTransparentColor( new Color( 0, 0, 0 ) );
// Draw a shape into LEAD2.
// Shape background
LEAD2.setShapeBackgroundStyle( (short) LTOCXU.EfxBackStyleConstants.EFX_BACKSTYLE_TRANSLUCENT );
// Shape location
LEAD2.setShapeTop( 0 );
LEAD2.setShapeLeft( 0 );
LEAD2.setShapeWidth( LEAD2.getBitmapWidth() );
LEAD2.setShapeHeight( LEAD2.getBitmapHeight() );
// Shape border
LEAD2.setShapeBorderColor( new Color( 255, 0, 0 ) );
LEAD2.setShapeBorderStyle( (short) LTOCXU.EfxBorderStyleConstants.EFX_BORDERSTYLE_SOLID );
LEAD2.setShapeBorderThickness( 5 );
LEAD2.setPatternStyle( (short) LTOCXU.PatternStyleEnum.EFX_PATTERN_TRANSPARENT );
// Draw the shape
LEAD2.DrawShape( (short) LTOCXU.EfxShapeConstants.EFX_SHAPE_STAR4, 0 );
// Draw text into LEAD3.
// Specify the text, font, and styles.
String strTest = "Text";
Font font = new Font( "Arial", 40, 0 );
LEAD3.setFont( font );
LEAD3.setTextAngle( (short) 450 );
LEAD3.setDrawFontColor( new Color( 0, 0, 255 ) ); // Blue
LEAD3.setTextStyle( (short) LTOCXU.EfxTextStyleConstants.EFX_TEXTSTYLE_NORMAL );
LEAD3.setTextAlign( (short) LTOCXU.EfxTextAlignConstants.EFX_TEXTALIGN_HCENTER_VCENTER );
// Set the location for the text.
LEAD3.setTextTop( 0 );
LEAD3.setTextLeft( 0 );
LEAD3.setTextWidth( LEAD3.getBitmapWidth() );
LEAD3.setTextHeight( LEAD3.getBitmapHeight() );
// Set the properties for drawing a rectangle behind the text.
LEAD3.setDrawPenStyle( (short) LTOCXU.DrawPenStyleConstants.DRAWPENSTYLE_SOLID );
LEAD3.setDrawPenColor( new Color( 255, 255, 0 ) );
LEAD3.setDrawMode( (short) LTOCXU.DrawModeConstants.DRAWMODE_COPY_PEN );
// Draw the rectangle, then draw the text.
LEAD3.DrawRectangle( 0, 0, LEAD3.getBitmapWidth(), LEAD3.getBitmapHeight() );
LEAD3.DrawText( strTest, 0 );
// Load an image into LEAD1.
LEAD1.Load( "c:\\lead\\images\\image1.cmp", (short) 0, (short) 0, (short) 1 );
LEAD1.setPaintSizeMode( (short) LTOCXU.PaintSizeModeConstants.PAINTSIZEMODE_ZOOM );
LEAD1.setPaintZoomFactor( 150 );
LEAD1.ForceRepaint();
// Turn off the effects.
LEAD1.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_NONE );
LEAD2.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_NONE );
LEAD3.setPaintEffect( (short) LTOCXU.EfxPaintEffectConstants.EFX_EFFECT_NONE );
}
4. Run your program to test it.