Imprecise GDI+ drawing algorithms? (circles)

6 views
Skip to first unread message

Joergen Bech

unread,
Feb 2, 2006, 7:23:27 AM2/2/06
to

I need to draw some tiny, filled, antialiased as well as
non-antialiased circles.

But if I do something like this (VB2005) (forget the buffer)...

---snip---
Private Sub DrawCircle(ByVal g As Graphics)
Dim bm As New Bitmap(256, 256,
Imaging.PixelFormat.Format32bppArgb)
Dim gbuf As Graphics = Graphics.FromImage(bm)
bm.SetPixel(0, 0, Color.Blue)
gbuf.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
gbuf.FillEllipse(Brushes.Black, 0, 0, 11, 11)
g.DrawImageUnscaled(bm, 0, 0)
gbuf.Dispose()
End Sub
---snip---

...I get an antialiased circle which, shall we say, does
not look the same if it was rotated 90 degrees.

Worse, when I turn off antialiasing, I get a 10x10 circle at
(1, 1) rather than a 12x12 one at (0, 0).

Suppose I wanted to create an icon editing program (this is
not the case, but the requirements are similar), I really need
better precision. If I draw a 12x12 circle in Photoshop, antialiased
or not, I get beautiful results.

Is there any way I can get GDI+ to deliver properly rendered
graphics?

Or will have I have to render everything myself, pixel by pixel
(using LockBitmap, etc)?

Or is there a 3rd-party library of better graphics primitives
rendering functions I can buy?

/Joergen Bech


Bob Powell [MVP]

unread,
Feb 2, 2006, 1:16:40 PM2/2/06
to
Try messing with the pixel offset mode too. :-)


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Joergen Bech" <jb...@post1.tele.dk> wrote in message
news:eat3u11md6bsco6lv...@4ax.com...

Joergen Bech

unread,
Feb 2, 2006, 1:58:30 PM2/2/06
to

I did, but though I tried a number of combinations,
I could not achieve the desired results.

I guess I'll have to create a test form, allowing
me to try out all possible combinations, but ...

/JB

Bob Powell [MVP]

unread,
Feb 4, 2006, 4:42:54 PM2/4/06
to
I ran your code and played with it a bit. After setting the pixel offset
mode to high quality there is a slight tonal assymetry but the problem of
physical pixel placement goes away.

I see the 10,10 circle at 1,1 when the pixel mode is set to lowest quality.
I agree, this is a lousy looking result.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Joergen Bech" <jb...@post1.tele.dk> wrote in message

news:del4u1d1o3iubpts3...@4ax.com...

Reply all
Reply to author
Forward
0 new messages