Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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



VB
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))
           'Form1.Label1.Text = cropRt.ToString
           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.
Posted
Comments
Sergey Alexandrovich Kryukov 24-Mar-15 19:20pm    
Make smaller images :-)
How much memory does one take?
—SA
[no name] 24-Mar-15 23:17pm    
You must look deeper and find what errors you are getting and then try to address them.
Member 10628309 25-Mar-15 12:19pm    
The program works perfectly on 4 of my machines. Three are running windows 7 professional(one is 32 bit the other two are 64 bit) the forth is running on windows 8.1 (64 bit). The machine that doesn't run properly is running on windows 7 professional (32 bit). The only difference I know of, is all of the machines that run the program properly have 4GB of RAM and the one that doesn't has 2GB. I did more investigation and found that the machine that doesn't work properly does not fire the mousedown and mousemove events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900