Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm new to gdi+ and I'm 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:

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!

Edited by PlausiblyDamp
  • 3 years later...
Posted
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'
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...