(sean)
1/11/2005 3:32:00 PM
Here is a sample that illustrates the error in the bounds which I
believe is then causing the error in flips and rotations.
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
public class DrawingSampleError : Form
{
Point[] m_controlPoints;
Point[] m_controlPoints2;
Rectangle m_cachedBounds;
float m_tension = 1.0F;
public static void Main()
{
Application.Run(new DrawingSampleError());
}
public DrawingSampleError()
{
Text = "Drawing Sample Error";
m_controlPoints = new Point[] { new Point(149, 199), new Point(199,
99), new Point(249, 199) };
m_controlPoints2 = new Point[] { new Point(29, 49), new Point(129,
149), new Point(29, 149) };
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
GetBounds(m_controlPoints);
grfx.DrawRectangle(new Pen(Color.Red), m_cachedBounds);
grfx.DrawCurve(new Pen(ForeColor), m_controlPoints);
GetBounds(m_controlPoints2);
grfx.DrawCurve(new Pen(Color.Blue), m_controlPoints2);
grfx.DrawRectangle(new Pen(Color.Red), m_cachedBounds);
}
protected Rectangle GetBounds(Point[] controlPoints)
{
using (GraphicsPath graphicsPath = new GraphicsPath())
{
graphicsPath.AddCurve(controlPoints, m_tension);
RectangleF boundsRectF = RectangleF.Empty;
try
{
using (Pen tempPen = new Pen(Color.Black, 1))
{
graphicsPath.Widen(tempPen);
}
boundsRectF = graphicsPath.GetBounds();
}
catch
{
}
m_cachedBounds = new Rectangle(
(int)Math.Ceiling(boundsRectF.Left),
(int)Math.Round(boundsRectF.Top) + 1,
(int)Math.Round(boundsRectF.Width),
(int)Math.Round(boundsRectF.Height));
}
return m_cachedBounds;
}
}
Thanks
sean