Search code examples
delphicanvasdelphi-7

Delphi 7 - Draw circle with transparent core using canvas


I'm trying to draw a simple circle using Delphi 7 and Canvas, and I'm doubt if what I want to do is possible.

As the following image, I want to draw a circle without a core/center:

Core transparent Pie

With Jerry Dodge suggestion:

enter image description here

  • I don't need of the red part, only the blue part.

Code used:

Canvas.Brush.Style := bsClear;
Canvas.Pen.Style := psSolid;
Canvas.Pen.Color := clGreen;
Canvas.Pen.Width := 20;
Canvas.Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);

Old information:

The background image is a simple TImage component and I draw the circle using this command:

Canvas.Brush.Color := clgreen;
Canvas.Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);

Is it possible?


Solved after Tom Brunberg and Jerry Dodge help!

Result:

tom


Thanks for all help!


Solution

  • I can think of a few ways to do this, but the easiest way is to use a large pen width with no fill. For example...

    Canvas.Brush.Style := bsClear;
    Canvas.Pen.Style := psSolid;
    Canvas.Pen.Color := clGreen;
    Canvas.Pen.Width := 50;
    Canvas.Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
    

    In your case however, Pie is not the proper approach, because it will also leave lines in the middle. You will have to use Arc instead.