this might be helpful also
private static void GetGraphicsPathTypeInfo( byte pathType, ref bool bCloseSubPath, ref bool bLine, ref bool bBezier )
{
bCloseSubPath = ( pathType & (byte)PathPointType.CloseSubpath ) > 0;
if ( bCloseSubPath )
{//remove CloseSubpath flag since its OR'ed in
pathType = (byte)(pathType & (~(byte)PathPointType.CloseSubpath));
}
bLine = ( pathType == (byte)PathPointType.Line );
bBezier = ( pathType == (byte)PathPointType.Bezier );
// JW - bezier and bezier3 appear to be the same
// bool bBezier3 = ( pathType == (byte)PathPointType.Bezier3 );
}
"Jason" <Ja***@mobiform.com> wrote in message news:uY*************@TK2MSFTNGP10.phx.gbl...
Heres a sample. Its going to make a number of polygons ( if there are is more than 1 path in the graphics path ) from the graphicss Path, each polygon is just a wrapper for a ArrayList of Point2Ds.
public static ArrayList CreateFromGraphicsPath( GraphicsPath graphicsPath )
{
ArrayList polygonList = new ArrayList();
bool bCloseSubPath = false;
bool bLine = false;
bool bBezier = false;
Polygon polygon = new Polygon();
for ( int i = 1; i < graphicsPath.PathPoints.Length; i++ )
{
GetGraphicsPathTypeInfo( (byte)graphicsPath.PathTypes[i], ref bCloseSubPath, ref bLine, ref bBezier );
if ( bBezier )
{
//this is a bezier point, solve for linear segments
polygon.AddPoint( new Point2D(graphicsPath.PathPoints[i-1]) );
i+=2;
//re-evaluate point type to see if we need to close
GetGraphicsPathTypeInfo( (byte)graphicsPath.PathTypes[i], ref bCloseSubPath, ref bLine, ref bBezier );
}
else
{//just a line point ... I assume
polygon.AddPoint( new Point2D(graphicsPath.PathPoints[i-1]) );
if ( bCloseSubPath && bLine )
{
polygon.AddPoint( new Point2D(graphicsPath.PathPoints[i]) );
}
}
if ( bCloseSubPath )
{
polygonList.Add( polygon );
polygon = new Polygon();
}
}
return polygonList;
}
And the top bit of polygon that covers adding/getting points
internal class Polygon
{
ArrayList m_Points = new ArrayList();
int m_CachedIsSimple = -1;
public Polygon( )
{
}
public void AddPoint ( Point2D point )
{
m_Points.Add( point );
}
public Point2D GetPoint ( int index )
{
Debug.Assert ( index >= 0 );
Debug.Assert ( index < GetPointCount() );
return m_Points[index] as Point2D;
//return (Point2D) m_Points[index];
}
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Jason,
It doesn't look like you are using structures though. Also, if you are
creating 2000 instances of these objects, that's going to take some time
(not 10 seconds, but definitely some overhead).
Can you show some code indicating how you are using these class
instances? That would give a better idea.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jason" <Ja***@mobiform.com> wrote in message
news:e%***************@TK2MSFTNGP09.phx.gbl...I have a graphicsPath object filled up with apporximately 2000 points, I am
coping them out into my own point class so I can do some extra operations
on
them, its super slow. In C++ this would be pretty fast, not instant, but
would take in the milliseconds, in c# is taking up to 10 seconds. The
operations I am doing are really complicated but blazing fast compared to
just getting the points out of the graphics path. I read that structs (
and
all by value entities ) are thread safe, which if its locking some mutex
or
semiphore could account for the bog. Is this what the problem is or could
it
be something else?
How can I speed up the process of getting the points out of the
graphicsPath?
heres a litte sample of my point class...just the construction
internal class Point2D
{
#region Member Variables
float m_X;
float m_Y;
#endregion
#region Constructor
public Point2D()
{
m_X = 0;
m_Y = 0;
}
public Point2D( float x, float y )
{
m_X = x;
m_Y = y;
}
public Point2D( Point2D pointToCopy )
{
m_X = pointToCopy.X;
m_Y = pointToCopy.Y;
}
public Point2D( PointF pointToCopy )
{
m_X = pointToCopy.X;
m_Y = pointToCopy.Y;
}
.....