Declaration
property OnDrawLayer: TIEDrawLayerExEvent;
Description
Occurs immediately after a layer is painted.
Parameter | Description |
Dest | The destination bitmap (usually the back buffer) |
LayerIndex | The layer index that we are drawing |
DestRect | Specifies the rectangle where the layer will be drawn on Dest (same as Layers[].ClientAreaBox) |
Note: With
TImageEnView.OnDrawLayer,
Dest is the entire image the layer has been painted to. With
OnBeforeDrawLayer,
Dest is only the layer as an image
ImageEnView Paint Events
The main paint events of TImageEnView are
OnDrawBackBuffer which occurs when the back buffer is painted and
OnDrawCanvas which occurs every time the canvas is painted. Generally
OnDrawBackBuffer is used for better performance, because the back buffer painting only occurs after the content is
updated. If you need constant custom drawing (e.g. to draw a marker at the current cursor position) then use
OnDrawCanvas.
In layer applications,
OnBeforeDrawLayer and
OnDrawLayer will occur while painting each individual layer. Use these methods if you need easy custom drawing upon each individual layer (e.g. a layer title). Generally
OnBeforeDrawLayer is best, unless you need to paint to the whole image (i.e. outside the area of the layer).
Other drawing events:
◼OnDrawBackground occurs when the background (area behind the image is painted) is painted to allow custom background styling
◼OnDrawLayerBox occurs when the
box around a
layer is painted to allow custom styling of the box
◼OnDrawLayerGrip occurs when the
grips of the selected
layer are drawn to allow custom grip styling
◼OnTransitionPaint occurs while
transitioning from one image to the next
◼OnPaint notifies whenever there is a paint event. It is not used for custom drawing
◼OnDrawPolygon notifies whenever a point of a polygonal selection is drawn
| Demos\LayerEditing\Layers_CustomDraw\LayersDraw.dpr |
procedure Tfmain.ImageEnView1DrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer; LayerRect: TRect);
var
rw, rh: Integer;
textX, textY: Integer;
sz: TSize;
begin
if LayerIndex = 0 then
exit;
// Draw ellipse
Dest.IECanvas.Brush.Style := bsClear;
Dest.IECanvas.Pen.Color := clYellow;
Dest.IECanvas.Pen.Style := psSolid;
Dest.IECanvas.Pen.Width := 5;
Dest.IECanvas.Ellipse( LayerRect.Left, LayerRect.Top, LayerRect.Right, LayerRect.Bottom );
// Text
rw := LayerRect.Right - LayerRect.Left;
rh := LayerRect.Bottom - LayerRect.Top;
Dest.IECanvas.Font.Size := 20;
Dest.IECanvas.Font.Style := [fsBold];
Dest.IECanvas.Font.Color := clRed;
sz := Dest.IECanvas.TextExtent( 'ImageEn!' );
textX := LayerRect.Left + ( rw - sz.cx ) div 2;
textY := LayerRect.Top + ( rh - sz.cy ) div 2;
// Draw rect behind text
Dest.IECanvas.Brush.Color := clWhite;
Dest.IECanvas.Brush.Style := bsSolid;
Dest.IECanvas.Brush.Transparency := 128;
Dest.IECanvas.FillRect( Rect( textX, textY, textX + sz.cx, textY + sz.cy ));
Dest.IECanvas.TextOut( textX, textY, 'ImageEn!' );
end;
// Display the index over the layer
procedure Tfmain.ImageEnView1DrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer; LayerRect: TRect);
var
txtRect: TRect;
begin
txtRect := Rect( LayerRect.Left + 10, LayerRect.Top + 10, LayerRect.Left + 40, LayerRect.Top + 40 );
with Dest.Canvas do
begin
// Simple example: Would be better to center text in filled rect
Brush.Color := clBlue;
FillRect( aRect );
Font.Color := clWhite;
Font.Height := 12;
Font.Style := [fsBold];
TextRect( txtRect, LayerRect.Left + 20, LayerRect.Top + 20, IntToStr( LayerIndex ));
end;
end;
// Use a Trackbar to darken the display of an image
procedure TForm1.ImageEnView1DrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer; LayerRect: TRect);
var
brightness: Integer;
begin
brightness := TrackBar1.Position; // 0=Black, 100=Full Brightness
IEAdjustBrightnessContrastSaturation( Dest, Round(brightness * 2.56), 0, 256, nil, nil );
end;