I am working on a GDI+ application in VB 2005 and can’t seem to find a solution for a problem with graphicspaths. This is a Windows application and I am allowing the user to freehand draw on a picturebox which has a background image loaded. I want to allow the user to erase any portion of the lines that have been drawn with an eraser tool. However, I don’t want the background image to appear erased. Is there a way to limit the eraser tool to the graphicspath. The only thing that comes to mind is some trick with regions, but, I’m not quite sure how to implement. Any graphics gurus out there who might be able to help? I’d be truly grateful. See code below:
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
If FractureFlag Then
mousePath.StartFigure()
ElseIf EraserFlag Then
mousepath2.StartFigure()
End If
End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
If FractureFlag Then
Try
mousePath.AddLine(e.X, e.Y + 21, e.X, e.Y + 21)
Catch
MsgBox("No way, Hose!")
End Try
ElseIf EraserFlag Then
Try
mousepath2.AddLine(e.X + 15, e.Y + 15, e.X + 15, e.Y + 15)
Catch
MsgBox("No way, Hose!")
End Try
End If
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
g.PixelOffsetMode = PixelOffsetMode.HighQuality
g.SmoothingMode = SmoothingMode.HighQuality
g.CompositingQuality = CompositingQuality.HighQuality
g.InterpolationMode = InterpolationMode.HighQualityBicubic
If FractureFlag Then
Try
myPenWidth = 2
myUserColor = (Color.Black)
myAlpha = 100
Dim CurrentPen As New _
Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth)
e.Graphics.DrawPath(CurrentPen, mousePath)
g.DrawPath(CurrentPen, mousePath)
Catch
MsgBox("Not happening!")
End Try
ElseIf EraserFlag Then
Try
myUserColor = (Color.White)
myAlpha = 255
myPenWidth = 15
Dim CurrentPen As New _
Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth)
e.Graphics.DrawPath(CurrentPen, mousepath2)
g2.DrawPath(CurrentPen, mousepath2)
Catch
MsgBox("Not happening too!")
End Try
End If
g3.DrawImage(bm, 0, 0)
g3.DrawImage(bm2, 0, 0)
e.Graphics.DrawImage(bm3, New Point(0, 0))
End Sub