Results 1 to 14 of 14

Thread: [RESOLVED] VS2010 - Out of memory exception while drawing

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2011
    Posts
    31

    [RESOLVED] VS2010 - Out of memory exception while drawing

    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:
    1. Public Class TestSig
    2.     Dim Alpha As Integer = 255
    3.     Dim penColor As New Color()
    4.     Dim penWidth As Single = 5
    5.     Dim bmp As New Bitmap(1024, 352)
    6.     Dim g As Graphics = Graphics.FromImage(bmp)
    7.     Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath()
    8.     Dim mousePoint1, mousePoint2 As New Point
    9.     Dim xStart, yStart As Integer
    10.     Dim CurrentPen As New Pen(Color.FromArgb(Alpha, penColor), penWidth)
    11.  
    12.     Private Sub TestSig_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    13.         bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
    14.         AddPath()
    15.     End Sub
    16.  
    17.     Private Sub AddPath()
    18.         Dim gr As Graphics = Graphics.FromImage(bmp)
    19.         gr.DrawPath(CurrentPen, mousePath) 'ERROR OCCURS HERE
    20.     End Sub
    21.  
    22.     Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    23.         'The below IfThen statement allows for the signee to start a new line
    24.         If (Abs(xStart - e.X) < 30) And (Abs(yStart - e.Y) < 30) Then
    25.             mousePath.AddLine(xStart, yStart, e.X, e.Y)
    26.         End If
    27.  
    28.         Dim area As New Rectangle(xStart, yStart, e.X, e.Y)
    29.         area.Inflate(1, 1)
    30.  
    31.         Me.PictureBox1.Invalidate(area)
    32.         Me.PictureBox1.Update()
    33.         mousePath.StartFigure()
    34.         xStart = e.X
    35.         yStart = e.Y
    36.         PictureBox1.Image = bmp
    37.     End Sub
    38.  
    39.     Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    40.         Me.PictureBox1.Image = bmp
    41.         AddPath()
    42.     End Sub
    Last edited by llDayo; Jan 27th, 2012 at 02:45 PM. Reason: resolved

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