I have a form created to act as a signature form. It will be used on an iPad via Citrix and that's not negotiable per my job so please don't make suggestions about developing it with Apple software. Anyway, on to the issue:
Since this will be on an iPad I cannot use an OnMouseDown event to handle the drawing with the form. It consists of a PictureBox where the signature will occur. It works fine unless the user gets "draw happy" and starts drawing for a while. After a little time an Out of Memory Exception occurs and the program crashes. I'm trying to figure out a way for this to not occur but have not had any luck. Does anyone have any suggestions on a better way than the code below?
vb.net Code:
Public Class TestSig Dim Alpha As Integer = 255 Dim penColor As New Color() Dim penWidth As Single = 5 Dim bmp As New Bitmap(1024, 352) Dim g As Graphics = Graphics.FromImage(bmp) Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath() Dim mousePoint1, mousePoint2 As New Point Dim xStart, yStart As Integer Dim CurrentPen As New Pen(Color.FromArgb(Alpha, penColor), penWidth) Private Sub TestSig_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height) AddPath() End Sub Private Sub AddPath() Dim gr As Graphics = Graphics.FromImage(bmp) gr.DrawPath(CurrentPen, mousePath) 'ERROR OCCURS HERE End Sub Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove 'The below IfThen statement allows for the signee to start a new line If (Abs(xStart - e.X) < 30) And (Abs(yStart - e.Y) < 30) Then mousePath.AddLine(xStart, yStart, e.X, e.Y) End If Dim area As New Rectangle(xStart, yStart, e.X, e.Y) area.Inflate(1, 1) Me.PictureBox1.Invalidate(area) Me.PictureBox1.Update() mousePath.StartFigure() xStart = e.X yStart = e.Y PictureBox1.Image = bmp End Sub Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Me.PictureBox1.Image = bmp AddPath() End Sub




Reply With Quote