Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Coordinates to Draw Image

Status
Not open for further replies.

Ddraig

MIS
Jul 16, 2004
97
0
0
US
Howdy,

I'm a bit stuck here at the moment. I'm working on drawing a line by line drawing using a string. I know I can do it with graphic.drawlines but this requires the coordinates to be in an array and I can not for the life of me figure out exactly how to do this.

I have a string that is being inputed that then based off of that it draws a line drawing. (This is for the floorplan/layout of a house from one of our land management databases.) It then takes the coordinates manipulates them and then dumps it to an image file.

I have it creating the image, and drawing the lines but it isn't using any of the coordinates, primarily because I'm stuck or confused as to how to use the drawlines method.

I'll paste the code I have so far. A lot of it has been commented out since I've been testing it. But basically I have an image control, and a button control and on the button click it draws the image. An help would be appricated.

'Dim drawLine As New drawLine
'x1 = CInt(Trim(txtX1.Text))
'y2 = CInt(Trim(txtY1.Text))
'x2 = CInt(Trim(txtX2.Text))
'y2 = CInt(Trim(txtY2.Text))
'drawLine.draw()

'lineStart.X = x1
'lineStart.Y = y1
'lineEnd.X = x2
'lineEnd.Y = y2
'myPen = Pens.Pink
'If IsPostBack = True Then
Try
Dim bmpImage As New Bitmap(350, 350)

'myGrf.DrawLine(myPen, lineStart, lineEnd)
Dim myPen As New Pen(Color.Blue, 2)


Dim grphImage As Graphics

grphImage = Graphics.FromImage(bmpImage)
grphImage.Clear(Color.White)

Dim intHeight As Integer
Dim intWidth As Integer
Dim intStartX As Integer
Dim intStartY As Integer

intHeight = 300
intWidth = 300

intStartX = intHeight / 2
intStartY = intWidth / 2

Dim intXCoord1 As Integer
Dim intYCoord1 As Integer
Dim intXCoord2 As Integer
Dim intYCoord2 As Integer
Dim strCoords As String


strCoords = "DU10/DU32/DU8/DR12/DR18/DR8/DD30/DD20/DL38/MU10/DL30/DU32/DR30/DD32/MU10/DL30/DU32/DR30/DD32/DU10/DL10/DD19/DR58/DU29/DL10/DD20/DL38/MR38/MU20/DR10/DU46/DL40/DU30/DL16/DD7/DR8/DD39/DR12/DU6/DR18/DD6/DR8/DD30/MU50/MR12/DU6/DR18/DD6/DL18/MU50/DU12/DL8/DD12/DR8/"
Dim aryCoords As Array

aryCoords = strCoords.Split("/")
Dim i As Integer
Dim endX As Integer
Dim endY As Integer
Dim midX As Integer
Dim midY As Integer
Dim startX As Integer
Dim starty As Integer

Dim topY As Integer
Dim bottomY As Integer
Dim rightX As Integer
Dim leftX As Integer

'For i = 0 To (aryCoords.Length - 2)
' Select Case aryCoords(i).Substring(0, 1)
' Case "D", "M"
' 'Draw
' Select Case aryCoords(i).Substring(1, 1)
' Case "U"
' 'Up
' endX = startX
' endY = starty - (CInt(Trim(aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2))))
' Case "D"
' 'Down
' endX = startX
' endY = starty + (CInt(Trim(aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2))))
' Case "R"
' 'Right
' endX = startX + (CInt(Trim(aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2))))
' endY = starty
' Case "L"
' 'Left
' endX = startX - (CInt(Trim(aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2))))
' endY = starty
' End Select
' If endX > rightX Then
' rightX = endX
' Else
' If endX < leftX Then
' leftX = endX
' End If
' End If

' If endY > topY Then
' topY = endY
' Else
' If endY < bottomY Then
' bottomY = endY
' End If
' End If

' startX = endX
' starty = endY

' Case "N"
' 'No Sketch
' End Select

'Next


For i = 0 To (aryCoords.Length - 2)
'Select Case strCoords.Substring(0, 1)
' Case "D", "M"
' Select Case strCoords.Substring(1, 1)
' Case "U"
' 'Up


' Case "D"
' 'Down
' Case "L"
' 'Left
' Case "R"
' 'Right
' End Select
'End Select



Select Case aryCoords(i).Substring(0, 1)
Case "D", "M"
'Draw
Select Case aryCoords(i).Substring(1, 1)
Case "U"
'Up
endX = startX
endY = starty - aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2)
midX = endX
midY = starty - ((starty - endY) / 2)
Case "D"
'Down
endX = startX
endY = starty + aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2)
midX = endX
midY = starty + ((endY - starty) / 2)
Case "R"
'Right
endX = startX + aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2)
endY = starty
midY = endY
midX = startX + ((endX - startX) / 2)
Case "L"
'Left
endX = startX - aryCoords.GetValue(i).ToString.Substring(2, aryCoords.GetValue(i).ToString.Length - 2)
endY = starty
midY = endY
midX = startX - ((startX - endX) / 2)
End Select
Case "N"
'No Sketch
End Select

'Response.Write(aryCoords.GetValue(i))
grphImage.DrawLine(myPen, startX, starty, endX, endY)

Dim mfnt As Font = New Font("Arial", 8, FontStyle.Regular)
intXCoord1 += 25
grphImage.DrawString(aryCoords.GetValue(i), mfnt, Brushes.Red, intXCoord1, 300)
' Make a StringFormat object that centers.
Dim sf As New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center

Next






'Dim i As Integer
'For i = 0 To 200 Step 5
' i = i + 5
' 'x1 += i
' y1 = i
' x2 = i
' 'y2 += i
' x1 = CInt(Trim(txtX1.Text))
' y2 = CInt(Trim(txtY1.Text))
' grphImage.DrawLine(myPen, x1, y1, x2, y2)
'Next

'grphImage.DrawLine(myPen, x1, y1, x2, y2)
'grphImage.DrawLine(myPen, 10, 200, 240, 200)
'Dim strCoords As String




'Dim scale As Integer = 2
'strCoords = "DU10/DU32/DU8/DR12/DR18/DR8/DD30/DD20/DL38/MU10/DL30/DU32/DR30/DD32/MU10/DL30/DU32/DR30/DD32/DU10/DL10/DD19/DR58/DU29/DL10/DD20/DL38/MR38/MU20/DR10/DU46/DL40/DU30/DL16/DD7/DR8/DD39/DR12/DU6/DR18/DD6/DR8/DD30/MU50/MR12/DU6/DR18/DD6/DL18/MU50/DU12/DL8/DD12/DR8/"
''Dim aryCoords As Array

'aryCoords = strCoords.Split("/")
'Dim i As Integer
'For i = 0 To aryCoords.Length
' 'Response.Write(aryCoords.GetValue(i) & "<br>")
' Select Case strCoords.Substring(0, 1)
' Case "D", "M"
' 'Draw
' Select Case strCoords.Substring(1, 1)
' Case "U"
' 'Up
' endX = intStartX
' endY = intStartY - (CInt(Trim(strCoords.Substring(2, strCoords.Length - 2)) * scale))
' midX = endX
' midY = startY - ((startY - endY) / 2)
' Case "D"
' 'Down
' endX = startX
' endY = startY + (CInt(Trim(strCoords.Substring(2, strCoords.Length - 2)) * scale))
' midX = endX
' midY = startY + ((endY - startY) / 2)
' Case "R"
' 'Right
' endX = startX + (CInt(Trim(strCoords.Substring(2, strCoords.Length - 2)) * scale))
' endY = startY
' midY = endY
' midX = startX + ((endX - startX) / 2)
' Case "L"
' 'Left
' endX = startX - (CInt(Trim(strCoords.Substring(2, strCoords.Length - 2)) * scale))
' endY = startY
' midY = endY
' midX = startX - ((startX - endX) / 2)
' End Select
' Case "N"
' 'No Sketch
' End Select
'Next





bmpImage.Save(Server.MapPath("") & "\temp.jpg", ImageFormat.Jpeg)
Catch ex As Exception
Dim lb As New Label
plcHolder.Controls.Add(lb)
lb.Text = ex.ToString

End Try
'End If
Image1.ImageUrl = Server.MapPath("") & "\temp.jpg"



-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top