Wednesday, May 23, 2007

C# Webcam Capture

Well I've tried to grab the stream from the IVideoWindow object in my application but to no avail. The only thing left is to grab a snapshot of the window control itself.

(If anyone can acutally manage to grab the stream please let me know!)

So I am left with this approach:



public virtual Bitmap CaptureControl( Control window )
{
Rectangle rect = window.RectangleToScreen( window.DisplayRectangle );
return capture(window, rect);
}

private Bitmap capture(Control window, Rectangle rect)
{
Bitmap memoryImage = null;

try
{
using (Graphics graphics = window.CreateGraphics())
{
memoryImage = new Bitmap(rect.Width, rect.Height, graphics);
using (Graphics memoryGraphics = Graphics.FromImage(memoryImage))
{
memoryGraphics .CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Capture failed");
}

return memoryImage;
}


Thursday, May 10, 2007

Exception has been thrown by the target of an invocation (c#)

"Exception has been thrown by the target of an invocation"

If you're getting this error, then it might be that your event log is becoming too full

You can clear your event log by going to:

Start -> Administrative Tools -> Event Viewer