|
-
Oct 21st, 2011, 05:11 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High
I have a graphics program and in it I use DrawEllipse plenty and when the pen thickness gets high like around 12 pixels or above you start to see these spikes. I'm using a PictureBox so double buffering is being used. Is there anything I can do to get rid of the "spikes". In the screenshot at top the pen thickness is at 19 and is 28 in the lower.
Last edited by EntityX; Oct 21st, 2011 at 05:32 PM.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 21st, 2011, 06:48 PM
#2
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
Have seen similar things when drawing svg... But anyway...
Instead of draw elipse... Have you tried adding them to a graphics path and rendering that?
Kris
-
Oct 21st, 2011, 08:08 PM
#3
Thread Starter
Fanatic Member
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
I use graphics paths also but here I want to use DrawEllipse. Perhaps there's no way to correct that problem. By greatly increasing the number of lines and then using a lower pen thickness I could get the same image but it would take a lot more computing power and probably run a lot slower.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 21st, 2011, 08:23 PM
#4
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
I mean like this:
vb Code:
Module GraphicsExt
<System.Runtime.CompilerServices.Extension()> _
Public Sub DrawPathEllipse(ByVal sender As Graphics, ByVal p As Pen, ByVal Rect As RectangleF)
Using gp As New System.Drawing.Drawing2D.GraphicsPath
gp.AddEllipse(Rect)
sender.DrawPath(p, gp)
End Using
End Sub
End Module
Then instead of calling graphics.DrawEllipse call graphics.DrawPathEllipse...
Try that and let me know
Kris
-
Oct 22nd, 2011, 12:52 AM
#5
Thread Starter
Fanatic Member
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
I appreciate the effort. I tried it but I get an identical result. I used screenshots to compare and went to the exact same frame using the two different methods and there's no improvement.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 22nd, 2011, 01:11 AM
#6
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
It looks like the spikes are only appearing when they are drawn Facing 0 90 180 and 270 degrees, might it not be that there is some error in your drawing code that is causing this ?
-
Oct 22nd, 2011, 04:05 AM
#7
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
Try changing the SmoothingMode of the Graphics object before drawing.
-
Oct 22nd, 2011, 04:58 AM
#8
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
Graphics.DrawEllipse produces increasingly angular results when you use a pen which is wider than the minor axis of the ellipse. It just wasn't designed for that eventuality! For example:
vb Code:
Using pn As New Pen(Brushes.Blue, 20) e.Graphics.DrawEllipse(pn, 100, 100, 50, 1) End Using
result:

Clearly your ellipses are approaching this kind of limit near the horizontal and vertical extremities of the loops. You can reduce the length of the spikes by setting the pen's MiterLimit to a smaller value (I think the default is 10), although the result still isn't exactly pretty:
vb Code:
pn.MiterLimit = 1 e.Graphics.DrawEllipse(pn, 100, 150, 50, 1)
result:

If you are able to look at GraphicsPath.AddEllipse/Graphics.DrawPath as an alternative, you might get better results by using the GraphicsPath.Flatten method with a small value (e.g. 0.05. I think the default is 0.25) to get more path points. On the whole, the best way to avoid this kind of thing would be to start using WPF instead of GDI+. But that's a whole 'nother story .
Afterthought: maybe the simplest way to fix this would be to switch to using FillEllipse when the eccentricity (ratio of x to y dimension) goes past a chosen upper or lower limit. Obviously you'd have to adjust the size of the filled ellipses to allow for the intended pen thickness.
BB
Last edited by boops boops; Oct 22nd, 2011 at 05:09 AM.
-
Oct 22nd, 2011, 10:05 AM
#9
Thread Starter
Fanatic Member
Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High
Boops, it was less than 500 billion eons before you helped me out again. I thought it was going to be at least 100 billion eons. I am indebted to you once again. Dropping the MiterLimit for the pen to 1 has as far as I'm concerned completely fixed the problem. I noticed that you can set MiterLimit to fractional values and it responds to fractional values. I can see a difference between 1.5 and 1 but not between 1 and 0.5. Using 1 seems to work quite well.
The MiterLimits in the below screenshots are from top to bottom 5 which looks about the same as before, 2 and 1 which looks best.
Last edited by EntityX; Oct 22nd, 2011 at 10:11 AM.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 22nd, 2011, 10:29 AM
#10
Thread Starter
Fanatic Member
Re: [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High
I did notice setting MiterLimit to 1 can sometimes create undesireable changes. In most cases I'm adjusting MiterLimit down but not in all cases. I found that you can set MiterLimit to -999 without any problem occurring and it appears you get the same result as setting it to 1. As far as I can see 1 and anything below 1 is all the same thing. I'm using this code in many places in my program.
MyPen.MiterLimit = 11 - PenWidth
If PenWidth is 1 then MiterLimit will be at 10 and if PenWidth is 50 then MiterLimit would be -39 which would be the same thing as 1.
Last edited by EntityX; Oct 22nd, 2011 at 02:32 PM.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Nov 10th, 2011, 04:57 AM
#11
Re: [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High
Been a while since i've looked @ this ... but how about drawing a perfect circle each time ... but transforming it to be the actual size you need? - i am sure this would work
Kris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|