How to load an image, draw on it with mouse like in paint prog and then save?
I have been reading this forum for the past few days. What i need is during run-time, to allow user to load an image, using his mouse to draw on it exactly like what he can do in paint programme.... a bit of scribble here and there and finally to save the completed picture.
So far after much searching around, I'd only manage to find the closest match with the following code, however, it only draw solid line and doesn't draw according to the path of mouse moved.
Appreciate if anyone can help, thanks!
Public Class Form6
Private mBmpSrce As Image
Private mBmpDest As Image
Private mDrawing As Boolean
Private mLastPoint As Point
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mBmpSrce = Bitmap.FromFile("c:\temp\test.bmp")
mBmpDest = New Bitmap(mBmpSrce)
End Sub
Private Sub Form6_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
mDrawing = Not mDrawing
If Not mDrawing Then
' Drawn the line, make mBmpSrce the new source image
mBmpSrce = CType(mBmpDest.Clone(), Image)
End If
mLastPoint = e.Location
End Sub
Private Sub Form6_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Not mDrawing Then Return
Dim gr As Graphics = Graphics.FromImage(mBmpDest)
gr.DrawImage(mBmpSrce, 0, 0)
gr.DrawLine(Pens.Blue, mLastPoint, e.Location)
gr.Dispose()
Invalidate()
End Sub
Private Sub Form6_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(mBmpDest, 0, 0)
End Sub
End Class

