Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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?

like image 936
JBeurer Avatar asked Jan 29 '13 12:01

JBeurer


1 Answers

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);
like image 106
Leff Avatar answered Nov 12 '22 15:11

Leff