473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert streamreader string to system.drawing. point?



I have an application where I want to redraw a polygon from points I
retrieve from a file.
The file is read with streamreader line by line each line contains the
points for each polygon.
Below is a typical line from my file.
500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748

Each set of x,y coordinates is separated by a space.

How can I read this into my points collection. If I currently try I get
can't convert issues.

Here's code I have been hacking and slashing
Dim blueBrush As New SolidBrush(Colo r.Blue)
Dim curvePoints As Point()
Dim part As Integer
Dim part2 As Integer
Dim pts As Point

Dim formGraphics2 As System.Drawing. Graphics = Me.CreateGraphi cs()

Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("P olygon.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
If line <"" Then
part =
Convert.ToInt32 (Microsoft.Visu alBasic.Left(li ne, 3))

part2 =
Convert.ToInt32 (Microsoft.Visu alBasic.Mid(lin e, 5, 3))
pts = (part,part2)
curvePoints = pts

End If

'formGraphics2. FillPolygon(blu eBrush, curvePoints)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLi ne("The file could not be read:")
Console.WriteLi ne(E.Message)
End Try

please respond via email if possible

--
Dave Bootsma
Bradenton Fl.
(941) 224-8298
Sep 8 '08 #1
5 3570
why not use split for your line ?
"Dave Bootsma" <da**********@v erizon.netwrote in message
news:uK******** ******@TK2MSFTN GP04.phx.gbl...
>

I have an application where I want to redraw a polygon from points I
retrieve from a file.
The file is read with streamreader line by line each line contains the
points for each polygon.
Below is a typical line from my file.
500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748

Each set of x,y coordinates is separated by a space.

How can I read this into my points collection. If I currently try I get
can't convert issues.

Here's code I have been hacking and slashing
Dim blueBrush As New SolidBrush(Colo r.Blue)
Dim curvePoints As Point()
Dim part As Integer
Dim part2 As Integer
Dim pts As Point

Dim formGraphics2 As System.Drawing. Graphics = Me.CreateGraphi cs()

Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("P olygon.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
If line <"" Then
part =
Convert.ToInt32 (Microsoft.Visu alBasic.Left(li ne, 3))

part2 =
Convert.ToInt32 (Microsoft.Visu alBasic.Mid(lin e, 5, 3))
pts = (part,part2)
curvePoints = pts

End If

'formGraphics2. FillPolygon(blu eBrush, curvePoints)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLi ne("The file could not be read:")
Console.WriteLi ne(E.Message)
End Try

please respond via email if possible

--
Dave Bootsma
Bradenton Fl.
(941) 224-8298
Sep 8 '08 #2
You can use the Split function a couple of times

Dim Rows(), Rows2() As String
Dim oRead As System.IO.Strea mReader
Dim EntireFile As String
oRead = File.OpenText(" c:\yourfile.txt ")
EntireFile = oRead.ReadToEnd ()
Rows = EntireFile.Spli t(CChar(" "))

For i As Integer = 0 to Rows.Length - 1
Rows2 = Rows(i).Split(C Char(",")
For j As Integer = 0 to Rows2.Length - 1
'--do your polygon thing
Next
Next
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 8 '08 #3
I've tried pts= .split(line," ")
but then I get type cannot be converted to 1-dimensional array
system.drawing. point

"Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
news:#q******** *****@TK2MSFTNG P06.phx.gbl...
why not use split for your line ?
"Dave Bootsma" <da**********@v erizon.netwrote in message
news:uK******** ******@TK2MSFTN GP04.phx.gbl...
>>

I have an application where I want to redraw a polygon from points I
retrieve from a file.
The file is read with streamreader line by line each line contains the
points for each polygon.
Below is a typical line from my file.
500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748

Each set of x,y coordinates is separated by a space.

How can I read this into my points collection. If I currently try I get
can't convert issues.

Here's code I have been hacking and slashing
Dim blueBrush As New SolidBrush(Colo r.Blue)
Dim curvePoints As Point()
Dim part As Integer
Dim part2 As Integer
Dim pts As Point

Dim formGraphics2 As System.Drawing. Graphics = Me.CreateGraphi cs()

Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("P olygon.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
If line <"" Then
part =
Convert.ToInt3 2(Microsoft.Vis ualBasic.Left(l ine, 3))

part2 =
Convert.ToInt3 2(Microsoft.Vis ualBasic.Mid(li ne, 5, 3))
pts = (part,part2)
curvePoints = pts

End If

'formGraphics2. FillPolygon(blu eBrush, curvePoints)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLi ne("The file could not be read:")
Console.WriteLi ne(E.Message)
End Try

please respond via email if possible

--
Dave Bootsma
Bradenton Fl.
(941) 224-8298

Sep 8 '08 #4
...
Dim k, m As Integer
For i As Integer = 0 to Rows.Length - 1
Rows2 = Rows(i).Split(C Char(",")
k = CInt(Rows2(0))
m = CInt(Rows2(1))
Pt = New Point(k, m)
Next
...

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 8 '08 #5
pts = line.Split(" "c)

or

pts = line.Split(New String() { " " }, StringSplitOpti ons.None)

You don't pass the string to Split(), you call Split() on the string
you with to split.

If you look at the IntelliSense you will see that String.Split takes
the separators as any of:
Char
Char array
String Array followed by StringSplitOpti ons

On Mon, 8 Sep 2008 17:52:14 -0400, "Dave Bootsma"
<da**********@v erizon.netwrote :
>I've tried pts= .split(line," ")
but then I get type cannot be converted to 1-dimensional array
system.drawing .point

"Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
news:#q******* ******@TK2MSFTN GP06.phx.gbl...
>why not use split for your line ?
"Dave Bootsma" <da**********@v erizon.netwrote in message
news:uK******* *******@TK2MSFT NGP04.phx.gbl.. .
>>>

I have an application where I want to redraw a polygon from points I
retrieve from a file.
The file is read with streamreader line by line each line contains the
points for each polygon.
Below is a typical line from my file.
500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748

Each set of x,y coordinates is separated by a space.

How can I read this into my points collection. If I currently try I get
can't convert issues.

Here's code I have been hacking and slashing
Dim blueBrush As New SolidBrush(Colo r.Blue)
Dim curvePoints As Point()
Dim part As Integer
Dim part2 As Integer
Dim pts As Point

Dim formGraphics2 As System.Drawing. Graphics = Me.CreateGraphi cs()

Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("P olygon.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
If line <"" Then
part =
Convert.ToInt 32(Microsoft.Vi sualBasic.Left( line, 3))

part2 =
Convert.ToInt 32(Microsoft.Vi sualBasic.Mid(l ine, 5, 3))
pts = (part,part2)
curvePoints = pts

End If

'formGraphics2. FillPolygon(blu eBrush, curvePoints)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLi ne("The file could not be read:")
Console.WriteLi ne(E.Message)
End Try

please respond via email if possible

--
Dave Bootsma
Bradenton Fl.
(941) 224-8298

Sep 8 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14206
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method, then use the GetThumbnailImage method to create a second Image. This second one is the one I want to get a FileStream from, so that I can then use...
11
7609
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
2
1494
by: Billy Greening | last post by:
I have an application in C# that was written as a bunch of individual CS files. I would like to combine these all into single solution that can be editied with the Visual Studio 2003 editor. Does anyone have any tips on how to quickly bring this code into the VS2003 environment? Below is a sample of the code for an about box: For this...
4
29017
by: John | last post by:
I want to convert the value of color.RGB of font object to hexadecimal value. How is it possible. Can some one help me. I want to do it through my code internally without using any third party tool. John
21
13066
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in...
4
2411
by: Harry Hudini | last post by:
Hi, I need to run exactly this code in an asp.net file when someone uploads an image, but i dont know C# and im having real issues converting it. If anyone can, could you convert it to VB.net for me to use ? Loads of karma in it for you :) <%@ Import Namespace="System.Collections" %>
6
3989
by: hb | last post by:
Hi, Would you please give me some idea to convert/decode a Base 64 encoded GIF image string to a *.gif file in ASP.Net? Thank you hb
1
5396
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but...
7
3384
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.