Results 1 to 6 of 6

Thread: Help required with GraphicsPath.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Help required with GraphicsPath.

    Dear All,
    I have a requirement like this:
    On my form there is a picture in which the image will be displayed. Now on the image I will be drawing a circle and I want to get only the values of the pixels which lie only within the circle co-ordinates. Can anybody out there please tell me how this could be accomplished.

    Thanks in advance.

    Regards,
    Susheelss.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,375

    Re: Help required with GraphicsPath.

    Take a look at this, some examples in vb and some math examples.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Help required with GraphicsPath.

    If you are using a GraphicsPath then you don't need any math(s). Just scan the picture in the X and Y directions. Assuming your circle is a GraphicsPath called gp, every pixel for which gp.IsVisible(X, Y) = True is inside the circle. BB

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Re: Help required with GraphicsPath.

    Thanks Mr.Boops and Mrdday9 for your valuable reply. I have attached the code I tried. But even when my code points to coordinates inside the circle I am getting reply as false. Can anybody please tell me what could be wrong in the code.

    Regards,
    Susheelss

    Code:
    Imports System
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    
    
    
    Public Class Form1
        Private CirclePath As GraphicsPath = New GraphicsPath
        Private _Color As Color
        Private _Pen As Pen
        Dim mp As New Point
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me._Color = Color.Red
            Me._Pen = New Pen(Me._Color, 6)
    
        End Sub
    
        Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
            mp = New Point(e.X, e.Y)
            Label2.Text = e.X & "," & e.Y
            Select Case e.Button
    
                Case Windows.Forms.MouseButtons.Left
    
    
    
                    If CirclePath.IsVisible(mp.X, mp.Y) = True Then
    
                        Label1.Text = "True"
    
                    ElseIf CirclePath.IsVisible(mp.X, mp.Y) = False Then
    
                        Label1.Text = "False"
    
                    End If
    
            End Select
    
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
            CirclePath.AddEllipse(200, 400, 200, 200)
            e.Graphics.DrawPath(_Pen, CirclePath)
    
        End Sub
    
    End Class

  5. #5

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Resolved Re: Help required with GraphicsPath.

    Thanks Mr. BOOPS. It worked. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width