JBeurer
JBeurer

Reputation: 1717

How to draw and fill a pixel-perfect, symmetric ellipse in WinForms, GDI+?

I need to draw (and fill) a pixel-perfect, non anti-alised, symmetric ellipse.

I've tried various combinations of InterpolationMode, SmoothingMode and PixelOffsetMode, but none of the combinations I have tried made sure that the ellipse stays symmetric and non anti-alised at all sizes.

Unfortunately MSDN documentation on the subject is not very accurate.

Ellipses not symmetric at all sizes

Code used for drawing:

g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.SmoothingMode = SmoothingMode.None;
g.PixelOffsetMode = PixelOffsetMode.None;                                
g.DrawEllipse(new Pen(colorPalette.SelectedColor), rect);

The same goes for filling non anti-alised ellipses.

Does anyone know solution for this?

Upvotes: 8

Views: 2425

Answers (2)

Vincent Krisna
Vincent Krisna

Reputation: 47

If you're not up to a perfect circle for retina display, based on Leff's answer, changing the smoothing mode to antialias or high quality will fix the pixelate circle.

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

Upvotes: 0

Leff
Leff

Reputation: 582

try this, is it perfect enough? :)

e.Graphics.InterpolationMode = InterpolationMode.Bilinear;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.SmoothingMode = SmoothingMode.None;
e.Graphics.FillEllipse(Brushes.Black, rect);

Upvotes: 2

Related Questions