I have a small test project for cropping that works fine on machines with 4GB of ram but does not work on machines with 2GB ram. How can I modify the code so that it works on the 2GB machines? Here is the guts of the code: It uses 2 forms, Form1 contains the stuff (a small datagridview) to be saved as a result of cropping.
Dim cropFrm As Form
Private Sub btnCrop_Click(sender As Object, e As EventArgs) Handles btnCrop.Click
cropFrm = New Form2
cropFrm.Show()
cropFrm.TopMost = True
End Sub
Private Sub Form2_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
StartX = e.X
StartY = e.Y
End Sub
Private Sub Form2_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
EndX = e.X
EndY = e.Y
wide = EndX - StartX
high = EndY - StartY
cropRt = New Rectangle((New Point(StartX, StartY)), New Size(wide, high))
Refresh()
End If
End Sub
Private Sub Form2_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawRectangle(New Pen(Color.Red, 2), cropRt)
End Sub
Private Sub CaptureCropRt()
Dim ScreenPos As Point = Me.PointToScreen(New Point(0, 0))
memoryImage = New Bitmap(wide, high)
Dim s As Size = New Size(wide, high)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(StartX + ScreenPos.X, StartY + ScreenPos.Y, 0, 0, s)
memoryGraphics.Dispose()
memoryImage.Dispose()
End Sub
There is another following sub to save the cropped image to a jpg file.