create an ellipse on an image

houlahan

New member
Joined
Jul 16, 2009
Messages
3
Programming Experience
1-3
ok so what i want to do is create an ellipse on a Picture Box on mouse click (like plotting points on a map) also when the user has created the ellipse i want the ellipes to display infomation about its self i.e the x and y coords and what its id is (this is determined by a listbox selection)and also be able to remove the point, and then load and save its self ether by button or automation on form load and when a new point it clicked. i know im asking alot i just wanted pointing in the right direction as i have no idea how to start this, i have a basic foundation but nothing to the extent to what i want it to be.
thanks in advanced
 
i think this piece of code can help you out . you can find mouse position by e.x and e.y & draw your ellipse by those coordinates.
if this code couldn't make anything clear for you , post whats obscure for you still :
VB.NET:
 Dim imagename As String = "c:\a.jpg" ' substitute your own image name here

        Dim mh As Image = Image.FromFile(imagename)

        Dim g As Graphics = Graphics.FromImage(mh)

        g.FillRectangle(Brushes.White, 5, 5, 100, 30)

        g.DrawRectangle(Pens.DarkBlue, 5, 5, 100, 30)

        Dim sf As StringFormat = CType(StringFormat.GenericTypographic.Clone(), StringFormat)

        sf.Alignment = StringAlignment.Center

        sf.LineAlignment = StringAlignment.Center



        g.DrawString(DateTime.Now.ToShortDateString(), 
New Font("tahoma", 14, GraphicsUnit.Point), Brushes.Black, New RectangleF(7, 7, 94, 25), sf)



        g.Dispose()

       mh.Save("C:\modifiedimage.jpg", Imaging.ImageFormat.Jpeg)
 
Last edited:
here is another code i worked on : hope it can help you too
VB.NET:
dim bmp as bitmap
 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        bmp = New Bitmap(Me.Width, Me.Height)
        Dim G As Graphics = Graphics.FromImage(bmp)

        G.Clear(Me.BackColor)


        G.DrawEllipse(New Pen(Color.Black), New Rectangle(10, 10, 30, 30))

        Me.BackgroundImage = bmp


    End Sub
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e 
As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown




        Dim G As Graphics = Graphics.FromImage(bmp)
        Dim x As Integer = e.X
        Dim y As Integer = e.Y

        G.DrawEllipse(New Pen(Color.Black), New Rectangle(x, y, 30, 30))

        Me.BackgroundImage = bmp

        Me.Refresh()
    End Sub
 
you can create an ellipse class that would hold the position, color, tag or some other info about the point you just clicked. After clicking you could add the instance of this object into an array. On mouse move you could iterate through al the elements in the array to check which ellipse the mouse is over. When over a certain ellipse you could draw a baloon like thing that would show the desired info. You could alter the code for other events like clicking onto an ellipse (right/left button), ...
 
Back
Top