Click here to Skip to main content
14,362,031 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, i got an issue with mi Windows Form Application. Im capturing images with my webcam and the program crashes when im trying to clone a bitmap with the bitmap.Clone() method. So i get this unhandled error: " The object is in use ". A try catch doesn't do the deal because i need that my picturBox refresh images, so the problem (object is in use)still goes on.

Crashes at:
Bitmap bitmap2 = bitmap.Clone(new Rectangle(0 ,0 ,320, 240), PixelFormat.Format24bppRgb)

As a suggestion, visual studio recommends me that: If i am using a Graphics objects after de GetHdc method, i have to call the ReleaseHdc method.


Here's a link to a photo of the problem
http://i43.photobucket.com/albums/e364/kedelvan/Sintiacutetulo.png

I dont have a clue of where i use a GetHdc method, i have never explicitly called it on my code.

I have to release something that i dont know.

I appreciate any help.
Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-13 19:03pm
   
There is nothing wrong with the line of code shown (and has nothing to do with System.Windows.Forms), so it might depend on context. If you can reproduce the problem on a complete (but very short, not related to your real code) sample, it can help.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

insted of
Bitmap bitmap2 = bitmap.Clone(new Rectangle(0 ,0 ,320, 240), PixelFormat.Format24bppRgb)
use
Bitmap bitmap2 = new Bitmap(bitmap)

this should solve the problem.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100