Drawing pie with parts excluded.
-
Hi all, I'm trying to find a way to draw a sort of section of a pie. Check this image: http://img186.imageshack.us/img186/9095/piesectionsqv7.png[^] I'm trying to draw an antialiased line around the blue section. I have filled that blue section by adding a pie to a path, then adding another pie using the size of the inner circle, which effectively removes the inner ellipse area. I can't get the same code working for drawing a border line. The only other way I can think of is using regions and Exclude, but this will break antialiasing. Am I missing something here? PS. I can't change my draw order, because the image could contain transparent sections. Thanks in advance
-
Hi all, I'm trying to find a way to draw a sort of section of a pie. Check this image: http://img186.imageshack.us/img186/9095/piesectionsqv7.png[^] I'm trying to draw an antialiased line around the blue section. I have filled that blue section by adding a pie to a path, then adding another pie using the size of the inner circle, which effectively removes the inner ellipse area. I can't get the same code working for drawing a border line. The only other way I can think of is using regions and Exclude, but this will break antialiasing. Am I missing something here? PS. I can't change my draw order, because the image could contain transparent sections. Thanks in advance
Err, sorry I didn't see GDI+ when I hovered over the Graphics section :zzz:
-
Err, sorry I didn't see GDI+ when I hovered over the Graphics section :zzz:
Hmmm. This is a tad messy, but it works:
public class PieWithExclusionEllipse : IDisposable { private GraphicsPath path; public GraphicsPath Path { get { return this.path; } } public PieWithExclusionEllipse(Rectangle pie, float startAngle, float sweepAngle, Rectangle exclusionEllipse) { GraphicsPath outerLine = new GraphicsPath(); GraphicsPath innerLine = new GraphicsPath(); outerLine = new GraphicsPath(); outerLine.AddPie(pie, startAngle, sweepAngle); if ((exclusionEllipse.Width != 0) && (exclusionEllipse.Height != 0)) { outerLine = this.removePointFromPath(outerLine, 0); outerLine = this.changePathPointType(outerLine, outerLine.PointCount - 1, PathPointType.Bezier); innerLine.AddPie(exclusionEllipse, startAngle, sweepAngle); innerLine = this.removePointFromPath(innerLine, 0); innerLine = this.changePathPointType(innerLine, innerLine.PointCount - 1, PathPointType.Bezier); innerLine.Reverse(); outerLine.AddPath(innerLine, true); outerLine.CloseFigure(); } this.path = outerLine; } private GraphicsPath changePathPointType(GraphicsPath path, int pointIndex, PathPointType pointType) { List points = new List(); List pointTypes = new List(); for (int index = 0; index < path.PointCount; index++) { points.Add(path.PathPoints[index]); if (index == pointIndex) { pointTypes.Add((byte)pointType); } else { pointTypes.Add(path.PathTypes[index]); } } return new GraphicsPath(points.ToArray(), pointTypes.ToArray()); } private GraphicsPath removePointFromPath(GraphicsPath path, int removeIndex) { List points = new List(); List pointTypes = new List(); for (int index = 0; index < path.PointCount; index++) { if (index != removeIndex) { points.Add(path.PathPoints[index]); pointTypes.Add(path.PathTypes[index]); } } return new GraphicsPath(points.ToArray(), pointTypes.ToArray()); } #region IDisposable Members public void Dispose() { if (this.path != null) { this.path.Dispose(); } } #endregion }
-
Hi all, I'm trying to find a way to draw a sort of section of a pie. Check this image: http://img186.imageshack.us/img186/9095/piesectionsqv7.png[^] I'm trying to draw an antialiased line around the blue section. I have filled that blue section by adding a pie to a path, then adding another pie using the size of the inner circle, which effectively removes the inner ellipse area. I can't get the same code working for drawing a border line. The only other way I can think of is using regions and Exclude, but this will break antialiasing. Am I missing something here? PS. I can't change my draw order, because the image could contain transparent sections. Thanks in advance
Why don't you use ZedGraph? there's an article posted on CP about it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001