CaptureFrame inside Thread
-
Hi I m using Directx.Capture library in C#. In capture.cs one function named as GrapImg() which is used to capture image from video. When I call the method GrapImg() from button click event it works fine. Now I need to call it within thread from the main form. But it gives an error Unable to cast COM object of type 'System.__ComObject' to interface type 'DShowNET.ISampleGrabber' public void GrapImg() { Trace.Write("IMG"); if (savedArray == null) { int size = videoInfoHeader.BmiHeader.ImageSize; if ((size < 1000) || (size > 16000000)) return; savedArray = new byte[size + 64000]; } sampGrabber.SetCallback(this, 1); } Error comes from the line sampGrabber.SetCallback(this, 1); Plz help me to solve this problem. Thanks in Advance
-
Hi I m using Directx.Capture library in C#. In capture.cs one function named as GrapImg() which is used to capture image from video. When I call the method GrapImg() from button click event it works fine. Now I need to call it within thread from the main form. But it gives an error Unable to cast COM object of type 'System.__ComObject' to interface type 'DShowNET.ISampleGrabber' public void GrapImg() { Trace.Write("IMG"); if (savedArray == null) { int size = videoInfoHeader.BmiHeader.ImageSize; if ((size < 1000) || (size > 16000000)) return; savedArray = new byte[size + 64000]; } sampGrabber.SetCallback(this, 1); } Error comes from the line sampGrabber.SetCallback(this, 1); Plz help me to solve this problem. Thanks in Advance
I just had the same issue. You have to call capture.GrapImg() in the same thread where the DirectX.Capture object was created. If you created it within the main form thread try using this.Invoke, that fixed it for me. Best, Carlos