saving drawing as text file
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
mr jets wrote:
for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1];
This obviously writes each point except the first and last twice.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
mr jets wrote:
for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1];
This obviously writes each point except the first and last twice.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
hello my friend..i know it writes each point twice one for idicate the start ..and other indicate the last..but the problem is when i draw 2 shapes like line the squar ..it writes SQUAR WORD TWICE in the text file as: squar {X=151,Y=49}{X=281,Y=143} squar {X=55,Y=96}{X=157,Y=202}
-
hello my friend..i know it writes each point twice one for idicate the start ..and other indicate the last..but the problem is when i draw 2 shapes like line the squar ..it writes SQUAR WORD TWICE in the text file as: squar {X=151,Y=49}{X=281,Y=143} squar {X=55,Y=96}{X=157,Y=202}
Thats because your code looks like this for(int j=0;j { streamWriter.WriteLine("squar"); Move the streamWriter.WriteLine("squar"); outside of the for loop Plus I would be tempted to actually store this information as XML - that way you can process all of the LINE shapes or all of the SQUARE shapes just by a simple xpath query - otherwise you'll be doing a lot of manual string comparisons and conversions when you read the file back in..... e.g
<shapes> <shape type="line> <points> <point x="100" y="100" /> <point x="200" y="100" /> <points> </shape> </shapes>
-- modified at 2:34 Friday 11th May, 2007 -
Thats because your code looks like this for(int j=0;j { streamWriter.WriteLine("squar"); Move the streamWriter.WriteLine("squar"); outside of the for loop Plus I would be tempted to actually store this information as XML - that way you can process all of the LINE shapes or all of the SQUARE shapes just by a simple xpath query - otherwise you'll be doing a lot of manual string comparisons and conversions when you read the file back in..... e.g
<shapes> <shape type="line> <points> <point x="100" y="100" /> <point x="200" y="100" /> <points> </shape> </shapes>
-- modified at 2:34 Friday 11th May, 2007ok i did that ..: if(drawwhat==1) { streamWriter.WriteLine("Line"); for(int j=0;j lessthan arraylist_points.Count;j++) { start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { streamWriter.WriteLine("squar"); for(int j=0;jlessthan arraylist_points.Count;j++) { start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } it will be saved in text file as : squar {X=131,Y=61}{X=265,Y=143} {X=68,Y=106}{X=146,Y=196} or u can recommend me ausfull article talkin about this..thats will be abetter idea..:sigh::confused: Regards:);
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
A basic rule of the forums is "Don't cross post". You have asked this question in other places as well. Please don't.
Deja View - the feeling that you've seen this post before.