Declaration
property OnBeforeDrawLayer: TIEDrawLayerEvent;
Description
Occurs immediately before a layer is painted to the back buffer.
It can be used to customize the bitmap that is drawn, including completely replacing the content (however you should NOT change the size of the layer).
| Parameter | Description |
| Dest | The layer as a bitmap (you may replace or draw to it, but avoid changing its size) |
| LayerIndex | The layer index that we are drawing |
Note:
◼With
TImageEnView.OnBeforeDrawLayer,
Dest is only the layer as an image. Whereas, with
OnDrawLayer,
Dest is the entire image the layer has been painted to.
◼If you need the layer rect, use
Layers[].
ClientAreaBox
◼Call
Update to force the layer to be redrawn.
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
Examples
// Show all layers as gray-scale
procedure TForm1.ImageEnView1BeforeDrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer);
var
aProc: TImageEnProc;
begin
aProc := TImageEnProc.CreateFromBitmap( Dest );
aProc.ConvertToGray();
aProc.Free();
end;
// Completely custom draw shape layer (which changes color as it is moved)
var
gLastChange: Cardinal;
gLastColor: TColor;
procedure Tfmain.ImageEnView1BeforeDrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer);
const
Pen_Width = 5;
Change_Frequency_MS = 333; // Change color every 1/3 second
begin
// Custom draw Ellipse layers only
if ImageEnView1.Layers[LayerIndex].Kind <> ielkShape then
exit;
if TIEShapeLayer( ImageEnView1.Layers[LayerIndex]).Shape <> iesEllipse then
exit;
// Make our image completely blank (filled with alpha
Dest.Allocate( Dest.Width, Dest.Height, clNone );
if Abs( GetTickCount() - gLastChange ) > Change_Frequency_MS then
begin
gLastColor := IERandomColor();
gLastChange := GetTickCount();
end;
// Draw our shape
with Dest.IECanvas do
begin
Brush.Style := bsSolid;
Brush.Color := gLastColor;
Brush.Transparency := 110;
Pen.Color := gLastColor;
Pen.Style := psSolid;
Pen.Width := Pen_Width;
Pen.Transparency := 255;
Ellipse( Pen_Width, Pen_Width, Dest.Width - Pen_Width, Dest.Height - Pen_Width );
// Draw our lines
MoveTo( 0, Dest.Height div 2 );
LineTo( Dest.Width, Dest.Height div 2 );
MoveTo( Dest.Width div 2, 0 );
LineTo( Dest.Width div 2, Dest.Height );
end;
// Draw our shape to the alpha channel (to make it visible)
with Dest.AlphaChannel.IECanvas do
begin
// paint brush and border
Brush.Style := bsSolid;
Brush.Color := clWhite;
Pen.Color := clWhite;
Pen.Style := psSolid;
Pen.Width := Pen_Width;
Ellipse( Pen_Width, Pen_Width, Dest.Width - Pen_Width, Dest.Height - Pen_Width );
end;
end;