The application shown in the above tutorial captures some area that is outside the Form. This is because we captured the image up to the form's width and size, which also includes the size of the non-client area. But the code we were written starts to capture the form from its client area. So, the client area of form + some additional space that includes the width and the height of the non-client area is taken. To, solve the above problem, rewrite your CaptureControlArea() function as follows, Private Function CaptureControlArea(ctrl As Control) As Bitmap Dim size As Size = ctrl.ClientSize Dim tmpBmp As New Bitmap(size.Width, size.Height) Dim g As Graphics g = Graphics.FromImage(tmpBmp) g.CopyFromScreen(ctrl.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(size.Width, size.Height)) Return tmpBmp End Function Here we first obtain the Client area of Form and then use that size alone. So, replace the CaptureControlArea() function shown in the tutorial with the code shown above. If you have any further doubts comment me.
it work fine, but i use aforge library so the code become like this Private Function capturearea(ByVal ct As Control) As Bitmap Dim tmpBmp As New Bitmap(ct.Width, ct.Height) Dim g As Graphics g = Graphics.FromImage(tmpBmp) g.CopyFromScreen(ct.PointToScreen(New System.Drawing.Point(0, 0)), New System.Drawing.Point(0, 0), New Size(size.Width, size.Height)) Return tmpBmp End Function and it seems the delete png dont work and it keep creating image over and over again.. the recorded video become laggy also, is there any solution ?
drive.google.com/open?id=0B1F2NP3dEaxYY2dtdTlyUWNoeVU the problem is when i start record process, i cant stop it and delete the .png file created,, it keep producing until you close it
Gunawan, I have viewed your code and I have found the problem. There are 2 problems in your code 1) When you click Stop Button, you have stopped Timer1 instead of Timer2. In Timer2 only, you have written the logic to capture the image.2) You have written the capturearea() function wrongly. a) In capturearea(), you have to first declare a size(you can give any other name also to avoid confusion) variable of the type Size and then obtain the size of the Control you have passed to it. b) g.CopyFromScreen(ctrl.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(size.Width, size.Height)) You have used AForge Library in your project. This library also has one structure named Point. So, if you have used simply New Point(0,0) means it will refer to the Point structure that is available in AForge Library. But you want to access the Point Class present in the System.Drawing namespace. So, rewrite the code as g.CopyFromScreen(ctrl.PointToScreen(New Drawing.Point(0, 0)), New Drawing.Point(0, 0), New Size(size.Width, size.Height)) So, update your code as follows, Private Function capturearea(ct As Control) As Bitmap Dim size As Size = ct.ClientSize Dim tmpBmp As New Bitmap(size.Width, size.Height) Dim g As Graphics g = Graphics.FromImage(tmpBmp) g.CopyFromScreen(ct.PointToScreen(New System.Drawing.Point(0, 0)), New System.Drawing.Point(0, 0), New Size(size.Width, size.Height)) Return tmpBmp ct.PointToScreen(New Drawing.Point(0, 0)) End Function You can view the modified code on the link drive.google.com/file/d/0Bz5zTBeKea6_Z3c2ZHR2MkFkeEk/view?usp=sharing
great tutorial, but the capture area of the form is not precise, theres still background screen that getting record, can you fix this pls ?
The application shown in the above tutorial captures some area that is outside the Form. This is because we captured the image up to the form's width and size, which also includes the size of the non-client area. But the code we were written starts to capture the form from its client area. So, the client area of form + some additional space that includes the width and the height of the non-client area is taken. To, solve the above problem, rewrite your CaptureControlArea() function as follows,
Private Function CaptureControlArea(ctrl As Control) As Bitmap
Dim size As Size = ctrl.ClientSize
Dim tmpBmp As New Bitmap(size.Width, size.Height)
Dim g As Graphics
g = Graphics.FromImage(tmpBmp)
g.CopyFromScreen(ctrl.PointToScreen(New Point(0, 0)), New Point(0, 0),
New Size(size.Width, size.Height))
Return tmpBmp
End Function
Here we first obtain the Client area of Form and then use that size alone. So, replace the CaptureControlArea() function shown in the tutorial with the code shown above.
If you have any further doubts comment me.
it work fine, but i use aforge library so the code become like this
Private Function capturearea(ByVal ct As Control) As Bitmap
Dim tmpBmp As New Bitmap(ct.Width, ct.Height)
Dim g As Graphics
g = Graphics.FromImage(tmpBmp)
g.CopyFromScreen(ct.PointToScreen(New System.Drawing.Point(0, 0)), New System.Drawing.Point(0, 0),
New Size(size.Width, size.Height))
Return tmpBmp
End Function
and it seems the delete png dont work and it keep creating image over and over again.. the recorded video become laggy also, is there any solution ?
I can't able to understand your question. So, please clearly explain your question and share your code through Google drive.
drive.google.com/open?id=0B1F2NP3dEaxYY2dtdTlyUWNoeVU
the problem is when i start record process, i cant stop it and delete the .png file created,, it keep producing until you close it
Gunawan, I have viewed your code and I have found the problem. There are 2 problems in your code
1) When you click Stop Button, you have stopped Timer1 instead of Timer2. In Timer2 only, you have written the logic to capture the image.2) You have written the capturearea() function wrongly. a) In capturearea(), you have to first declare a size(you can give any other name also to avoid confusion) variable of the type Size and then obtain the size of the Control you have passed to it. b) g.CopyFromScreen(ctrl.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(size.Width, size.Height)) You have used AForge Library in your project. This library also has one structure named Point. So, if you have used simply New Point(0,0) means it will refer to the Point structure that is available in AForge Library. But you want to access the Point Class present in the System.Drawing namespace. So, rewrite the code as g.CopyFromScreen(ctrl.PointToScreen(New Drawing.Point(0, 0)), New Drawing.Point(0, 0),
New Size(size.Width, size.Height)) So, update your code as follows,
Private Function capturearea(ct As Control) As Bitmap
Dim size As Size = ct.ClientSize
Dim tmpBmp As New Bitmap(size.Width, size.Height)
Dim g As Graphics
g = Graphics.FromImage(tmpBmp)
g.CopyFromScreen(ct.PointToScreen(New System.Drawing.Point(0, 0)), New System.Drawing.Point(0, 0),
New Size(size.Width, size.Height))
Return tmpBmp
ct.PointToScreen(New Drawing.Point(0, 0))
End Function
You can view the modified code on the link drive.google.com/file/d/0Bz5zTBeKea6_Z3c2ZHR2MkFkeEk/view?usp=sharing