Windows API graphics function Ellipse circle anomaly

Brian 1 Reputation point
2022-05-29T19:31:47.587+00:00

I have used the Windows API function Ellipse for many years.

I have seen that when the Ellipse function draws a circle with an even number diameter,
the top side and right side have different pixel counts.

The function call is usually like this for a circle of diameter of 40 pixels;
HDC hdc; // Device context
hdc = GetDC( Windows handle );
Ellipse( hdc, 0, 0, 40, 40 );
ReleaseDC( Windows handle, hdc );

The first picture is an actual size screen capture.

206409-ellipsescreen40-220529-01.png

The second picture is enlarged by a factor of eight to show the pixels better.

206467-ellipsescreen40-220529-02.png

Note that there are 4 pixels at the top and 6 pixels on the right.

Since a circle is supposed to by symmetric this looks a little unusual.

Does anyone have an answer?

Am I calling the function Ellipse wrong?

Thank you.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,436 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Castorix31 81,846 Reputation points
    2022-05-29T20:40:48.86+00:00

    Ellipse in GDI is not a real ellipse and uses PolyBezier

    Direct2D Ellipse is better (with anti-aliasing)

    A comparison GDI/Direct2D with the Ellipse sample you posted :

    Original size :

    206493-ellipse-1.jpg

    Zoom :

    206494-ellipse-zoom.jpg

    0 comments No comments

  2. Brian 1 Reputation point
    2022-05-30T00:54:54.683+00:00

    I tried SetArcDirection( hdc, AD_CLOCKWISE ) and it seemed to work - but why?


  3. Brian 1 Reputation point
    2022-05-31T02:46:24.377+00:00

    As suggested I ran the program with SetArcDirection and size 46 pixels:

    SetArcDirection( hdc, AD_CLOCKWISE );
    Ellipse( hdc, 0, 0, 46, 46 );

    The first picture is an actual size screen capture.

    206903-ellipsescreen46-220530-01.png

    The second picture is enlarged by a factor of eight to show the pixels better.

    206854-ellipsescreen46-220530-02.png

    Note that there are 6 pixels at the top and 4 pixels on the right.