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.
Re: Help required with GraphicsPath.
Take a look at this, some examples in vb and some math examples.
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
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
Re: Help required with GraphicsPath.
Put CirclePath.AddEllipse in the Load sub instead of the Paint sub.
BB
Re: Help required with GraphicsPath.
Thanks Mr. BOOPS. It worked. Thank you very much.