Plotting points in gdi+

JerryD

New member
Joined
Nov 3, 2003
Messages
1
Im new to gdi+ and Im trying to plot 6x6 pixel ellipses on a map to show positioning. The problem is that I am not able to plot the ellipse precisely to my expected x,y coordinates. It it plotting high and to the left. Any suggestions?

here is my code:
Code:
Dim firstPoint As Boolean = True
Dim mapName As String
myRead = myCom.ExecuteReader
Dim oCanvas As Bitmap

Dim g As Graphics

Do While myRead.Read
If firstPoint = True Then
firstPoint = False
mapName = myRead.Item("map_name")

We load an existing bitmap 
oCanvas = CType(Image.FromFile(Server.MapPath("library/images/maps/" + mapName)), Bitmap)
g = Graphics.FromImage(oCanvas)
g.ResetTransform()

***********Draw points on map ***************************************
g.FillEllipse(Brushes.Red, myRead.Item("x_coor"), myRead.Item("y_coor"), 6, 6)
g.ResetTransform()
Else
If mapName = myRead.Item("map_name") Then
g.FillEllipse(Brushes.Black, myRead.Item("x_coor"), myRead.Item("y_coor"), 6, 6)
g.ResetTransform()
Else
Exit Do
End If
End If
Loop
********************************************************************
resize the image
Dim mapWidth = oCanvas.Width * 0.75
Dim mapHeight = oCanvas.Height * 0.75

output new image with different size
Dim outputBitMap As Bitmap = New Bitmap(oCanvas, mapWidth, mapHeight)
Response.ContentType = "image/jpeg"
outputBitMap.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()

Cleanup
g.Dispose()
oCanvas.Dispose()
f1.Dispose()
f3.Dispose()

Thanks!
 
Last edited by a moderator:
Hi - this seems like an issue around needing to add or subtract half the height and half the width of the ellipse before plotting it to position it properly on the Pixel of Interest
 
With the Draw/FillElipse methods, you specify a bounding rectangle as opposed to a center and a size. So, like GeoManiac said, you need to subtract the radius from the X and Y values.
 
Back
Top