Using Contours

Tutorials ››
Parent Previous Next

Contours are transparent shapes that appear with a thin (1 pixel wide ) outline regardless of zoom factor.ImagePainter implements contours as properties of certain standard figures. These are:





Besides, contours are also available with TSelector when its shape is shRectangular, shEllpitic and shPolygonic.

Being precision instruments, contours are basically selection tools. Using contours with the standard shapes you can create a multi selector environment something that is not possible with TSelector which can only have one instance at a time. Contours are regarded as temporary figures and are not saved with the image, except if you save them in document (IPD) files.

To make a figure a contour, simply set its Contoured property: MyFigure.Contoured := True; Though public on the TFigure level, the Contoured property has only effect for the above mentioned figures. For other figures it will always stay false.

ImagePainter maintains a list of all the contours in an image: Read the TImagePainter.Contours, TImagePainter.ContourCount and TFigure.ContourIndex properties. Note that the standard Selector (if contoured) is not part of the list.

Contour measurements

As contours only appear with a thin line border, you will (except for rectangles) expect a visual mismatch between a normal, none contoured figure and its contoured companion. This is because the contour outline follows the figure region. The pixels inside the border of the first figure below are in fact what you get when you request its content. It's not that easy to predict which pixels are inside the shape of the thick lined figure.

To measure the width and height of a contour use ContourWidth and ContourHeight instead of Width and Height. To obtain the rectangle use ContourRect instead of FigRect..

Tuning a contour

A contour can have to modes: pixelated or not. A none pixelated contour draws a smooth shape, the outline possibly, in zoom mode, crossing the pixel cells. Pixelating forces the outline to snap to the edges of the cells, like in the first figure above.This makes it easier to determine which pixels are selected. You turn pixelating on and off with the TFigure.PixelateContour property. Default is false.

With small or narrow polygonic and elliptic shapes, you will often see blind lines without content. Such lines can be removed by turning on the TFigure.TrimContour property.


The above examples shows an untrimmed and trimmed ellipse with the same base size. In this case trimming makes the figure 4 pixels shorter which will be reflected in the ContourWidth and and ContourRect properties.


In this version trimming has only effect for ellipses. Trimming requires pixelation to work.

Outline styles

A contour can have a static outline or an animated cycling dot style. To show an animate style set the TImagePainter.ContourCycling to true. Set the color and size of the dots with the CyclingDotColor1, CyclingDotColor2 and CyclingDotSize respectively.

If you choose a static outline, you set color, and style of the FigAttributes.Pen property.

To gain utterly control of outline behavior you can respond to the OnDrawContour event handler. See that topic for more information.

Obtaining contour content

To copy the content of a contour to the clipboard, call TFigure.CopyContourContent;

To obtain a bitmap footprint of a contour call TFigure.ContourAsBitmap

To get the points of the interior call TFigure.GetPoints.