Forum > LCL

How to draw outlined ellipse?

(1/1)

Leledumbo:
For rectangle, there are Canvas.Rectangle (outlined) and Canvas.FillRect (filled). But for ellipse, there's only Canvas.Ellipse!

DougNettleton:
I'm not an expert on this stuff, but ...

  Image1.Canvas.Pen.Color := clWhite;
  Image1.Canvas.Brush.Color := clWhite;
  Image1.Canvas.Rectangle(0,0,Image1.Width, Image1.Height);

and

  Image1.Canvas.Pen.Color := clBlack;
  Image1.Canvas.Brush.Color := clWhite;
  Image1.Canvas.FillRect(0,0,Image1.Width, Image1.Height);

appear to be equivalent

if you try the following ...

  Image1.Canvas.Brush.Color := clWhite;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Ellipse(6,6,39,64);

  Image1.Canvas.Pen.Color := clBlack;
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Ellipse(106,106,139,164);

  Image1.Canvas.Rectangle(206,206,239,264);

I think you'll see that Ellipse and Rectangle work the same way, i.e. the shape is the Pen color and they're filled with the Brush color.  

If you're trying to draw an ellipse over multiple other objects, without disturbing their contents, I guess you could use Arc like...

  Image1.Canvas.Arc(106,6,139,64,139,6,139,6);

or even simpler ...

  Image1.Canvas.Arc(106,6,139,64,0,0,0,0);

And for a similar line rectangle ...

  Image1.Canvas.MoveTo(206,6);
  Image1.Canvas.LineTo(206,64);
  Image1.Canvas.LineTo(239,64);
  Image1.Canvas.LineTo(239,6);
  Image1.Canvas.LineTo(206,6);

or

  Image1.Canvas.Polyline([point(206,6),point(206,64),point(239,64),Point(239,6),point(206,6)]);


HTH,

Doug

Leledumbo:

--- Quote ---If you're trying to draw an ellipse over multiple other objects, without disturbing their contents, I guess you could use Arc
--- End quote ---

Quite a lot to type, but better than nothing. Thanks. I'll make a wrapper for it.

johnnylee:
Late, but I think this is a simpler solution, with the current Lazarus as of 2018, and it can still help anyone landing in this thread when they google search, (which included me).

Canvas.Brush.Style := bsClear;

Navigation

[0] Message Index

Go to full version