While searching for capturing video with a webcam I god the following code.It gives two errors.Says:The type or namespace name 'WebcamEventArgs' does not exit in the namespace 'WebCam_Capture' (are you missing an assembly reference?) - using System;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Drawing;
-
using System.Data;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
namespace WebCam_Capture
-
{
-
/// <summary>
-
/// Summary description for UserControl1.
-
/// </summary>
-
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] //
-
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] //
-
public class WebCamCapture : System.Windows.Forms.UserControl
-
{
-
private System.ComponentModel.IContainer components;
-
private System.Windows.Forms.Timer timer1;
-
//
-
private int m_TimeToCapture_milliseconds = 100;
-
private int m_Width = 320;
-
private int m_Height = 240;
-
private int mCapHwnd;
-
private ulong m_FrameNumber = 0;
-
//
-
private WebCam_Capture.WebcamEventArgs x = new WebCam_Capture.WebcamEventArgs();
-
private IDataObject tempObj;
-
private System.Drawing.Image tempImg;
-
private bool bStopped = true;
-
//
-
public delegate void WebCamEventHandler(object source, WebCam_Capture.WebcamEventArgs e);
-
//
-
public event WebCamEventHandler ImageCaptured;
-
#region API Declarations
-
[DllImport("user32", EntryPoint = "SendMessage")]
-
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
-
[DllImport("avicap32.dll", EntryPoint = "capCreateCaptureWindowA")]
-
public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
-
[DllImport("user32", EntryPoint = "OpenClipboard")]
-
public static extern int OpenClipboard(int hWnd);
-
[DllImport("user32", EntryPoint = "EmptyClipboard")]
-
public static extern int EmptyClipboard();
-
[DllImport("user32", EntryPoint = "CloseClipboard")]
-
public static extern int CloseClipboard();
-
#endregion
-
#region API Constants
-
public const int WM_USER = 1024;
-
public const int WM_CAP_CONNECT = 1034;
-
public const int WM_CAP_DISCONNECT = 1035;
-
public const int WM_CAP_GET_FRAME = 1084;
-
public const int WM_CAP_COPY = 1054;
-
public const int WM_CAP_START = WM_USER;
-
public const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41;
-
public const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;
-
public const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
-
public const int WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44;
-
public const int WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45;
-
public const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46;
-
public const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
-
#endregion
-
#region NOTES
-
-
#endregion
-
-
public WebCamCapture()
-
{
-
InitializeComponent();
-
}
-
/// <summary>
-
/// Override the class's finalize method, so we can stop
-
/// the video capture on exit
-
/// </summary>
-
~WebCamCapture()
-
{
-
this.Stop();
-
}
-
protected override void Dispose(bool disposing)
-
{
-
if (disposing)
-
{
-
if (components != null)
-
components.Dispose();
-
}
-
base.Dispose(disposing);
-
}
-
#region Component Designer generated code
-
/// <summary>
-
/// Required method for Designer support - do not modify
-
/// the contents of this method with the code editor.
-
/// </summary>
-
private void InitializeComponent()
-
{
-
this.components = new System.ComponentModel.Container();
-
this.timer1 = new System.Windows.Forms.Timer(this.components);
-
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
-
this.Name = "WebCamCapture";
-
this.Size = new System.Drawing.Size(342, 252);
-
this.Load += new System.EventHandler(this.WebCamCapture_Load);
-
}
-
#endregion
-
#region Control Properties
-
public int TimeToCapture_milliseconds
-
{
-
get
-
{ return m_TimeToCapture_milliseconds; }
-
set
-
{ m_TimeToCapture_milliseconds = value; }
-
}
-
/// <summary>
-
/// The height of the video capture image
-
/// </summary>
-
public int CaptureHeight
-
{
-
get
-
{ return m_Height; }
-
-
set
-
{ m_Height = value; }
-
}
-
/// <summary>
-
/// </summary>
-
public int CaptureWidth
-
{
-
get
-
{ return m_Width; }
-
set
-
{ m_Width = value; }
-
}
-
/// <summary>
-
/// </summary>
-
public ulong FrameNumber
-
{
-
get
-
{ return m_FrameNumber; }
-
set
-
{ m_FrameNumber = value; }
-
}
-
#endregion
-
#region Start and Stop Capture Functions
-
/// <summary>
-
/// </summary>
-
/// <param name="FrameNumber">the frame number to start at.
-
/// Set to 0 to let the control allocate the frame number</param>
-
public void Start(ulong FrameNum)
-
{
-
try
-
{
-
this.Stop();
-
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, m_Width, m_Height, this.Handle.ToInt32(), 0);
-
Application.DoEvents();
-
SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);
-
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0);
-
m_FrameNumber = FrameNum;
-
this.timer1.Interval = m_TimeToCapture_milliseconds;
-
bStopped = false;
-
this.timer1.Start();
-
}
-
catch (Exception excep)
-
{
-
MessageBox.Show("An error ocurred while starting the video capture. Check that your webcamera is connected properly and turned on.\r\n\n" + excep.Message);
-
this.Stop();
-
}
-
}
-
/// <summary>
-
/// Stops the video capture
-
/// </summary>
-
public void Stop()
-
{
-
try
-
{
-
bStopped = true;
-
this.timer1.Stop();
-
Application.DoEvents();
-
SendMessage(mCapHwnd, WM_CAP_DISCONNECT, 0, 0);
-
}
-
catch (Exception excep)
-
{ }
-
}
-
#endregion
-
#region Video Capture Code
-
/// <summary>
-
/// Capture the next frame from the video feed
-
/// </summary>
-
private void timer1_Tick(object sender, System.EventArgs e)
-
{
-
try
-
{
-
this.timer1.Stop();
-
SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);
-
SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);
-
if (ImageCaptured != null)
-
{
-
tempObj = Clipboard.GetDataObject();
-
tempImg = (System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);
-
-
x.WebCamImage = tempImg.GetThumbnailImage(m_Width, m_Height, null, System.IntPtr.Zero);
-
this.ImageCaptured(this, x);
-
}
-
Application.DoEvents();
-
if (!bStopped)
-
this.timer1.Start();
-
}
-
catch (Exception excep)
-
{
-
MessageBox.Show("An error ocurred while capturing the video image. The video capture will now be terminated.\r\n\n" + excep.Message);
-
this.Stop(); }
-
}
-
#endregion
-
private void WebCamCapture_Load(object sender, System.EventArgs e)
-
{
-
-
}
-
}
-
}
Can anybody help me?
3 18243
I had the same problem. I changed the code, this works for me... - using System;
-
using System.Collections;
-
using System.ComponentModel;
-
using System.Drawing;
-
using System.Data;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
-
namespace WebcamWhiteboard
-
{
-
/// <summary>
-
/// Summary description for UserControl1.
-
/// </summary>
-
[System.Drawing.ToolboxBitmap(typeof(WebCamCapture), "CAMERA.ICO")] // toolbox bitmap
-
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))] // make composite
-
public class WebCamCapture : System.Windows.Forms.UserControl
-
{
-
private System.ComponentModel.IContainer components;
-
private System.Windows.Forms.Timer timer1;
-
-
// property variables
-
private int m_TimeToCapture_milliseconds = 100;
-
private int m_Width = 320;
-
private int m_Height = 240;
-
private int mCapHwnd;
-
private ulong m_FrameNumber = 0;
-
-
/// <summary>
-
/// This was missing.
-
/// </summary>
-
private class WebcamEventArgs
-
{
-
public Image WebCamImage;
-
}
-
-
// global variables to make the video capture go faster
-
private WebCamCapture.WebcamEventArgs x = new WebCamCapture.WebcamEventArgs();
-
private IDataObject tempObj;
-
private System.Drawing.Image tempImg;
-
private bool bStopped = true;
-
-
// event delegate
-
public delegate void WebCamEventHandler(object source, WebCamCapture.WebcamEventArgs e);
-
// fired when a new image is captured
-
public event WebCamEventHandler ImageCaptured;
-
-
#region API Declarations
-
-
[DllImport("user32", EntryPoint = "SendMessage")]
-
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
-
-
[DllImport("avicap32.dll", EntryPoint = "capCreateCaptureWindowA")]
-
public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
-
-
[DllImport("user32", EntryPoint = "OpenClipboard")]
-
public static extern int OpenClipboard(int hWnd);
-
-
[DllImport("user32", EntryPoint = "EmptyClipboard")]
-
public static extern int EmptyClipboard();
-
-
[DllImport("user32", EntryPoint = "CloseClipboard")]
-
public static extern int CloseClipboard();
-
-
#endregion
-
-
#region API Constants
-
-
public const int WM_USER = 1024;
-
-
public const int WM_CAP_CONNECT = 1034;
-
public const int WM_CAP_DISCONNECT = 1035;
-
public const int WM_CAP_GET_FRAME = 1084;
-
public const int WM_CAP_COPY = 1054;
-
-
public const int WM_CAP_START = WM_USER;
-
-
public const int WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41;
-
public const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;
-
public const int WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
-
public const int WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44;
-
public const int WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45;
-
public const int WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46;
-
public const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
-
-
#endregion
-
-
#region NOTES
-
-
/*
-
* If you want to allow the user to change the display size and
-
* color format of the video capture, call:
-
* SendMessage (mCapHwnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0);
-
* You will need to requery the capture device to get the new settings
-
*/
-
-
#endregion
-
-
-
public WebCamCapture()
-
{
-
// This call is required by the Windows.Forms Form Designer.
-
InitializeComponent();
-
}
-
-
/// <summary>
-
/// Override the class's finalize method, so we can stop
-
/// the video capture on exit
-
/// </summary>
-
~WebCamCapture()
-
{
-
this.Stop();
-
}
-
-
/// <summary>
-
/// Clean up any resources being used.
-
/// </summary>
-
protected override void Dispose(bool disposing)
-
{
-
if (disposing)
-
{
-
-
if (components != null)
-
components.Dispose();
-
}
-
base.Dispose(disposing);
-
}
-
-
#region Component Designer generated code
-
/// <summary>
-
/// Required method for Designer support - do not modify
-
/// the contents of this method with the code editor.
-
/// </summary>
-
private void InitializeComponent()
-
{
-
this.components = new System.ComponentModel.Container();
-
this.timer1 = new System.Windows.Forms.Timer(this.components);
-
//
-
// timer1
-
//
-
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
-
//
-
// WebCamCapture
-
//
-
this.Name = "WebCamCapture";
-
this.Size = new System.Drawing.Size(342, 252);
-
this.Load += new System.EventHandler(this.WebCamCapture_Load);
-
-
}
-
#endregion
-
-
#region Control Properties
-
-
/// <summary>
-
/// The time intervale between frame captures
-
/// </summary>
-
public int TimeToCapture_milliseconds
-
{
-
get
-
{ return m_TimeToCapture_milliseconds; }
-
-
set
-
{ m_TimeToCapture_milliseconds = value; }
-
}
-
-
/// <summary>
-
/// The height of the video capture image
-
/// </summary>
-
public int CaptureHeight
-
{
-
get
-
{ return m_Height; }
-
-
set
-
{ m_Height = value; }
-
}
-
-
/// <summary>
-
/// The width of the video capture image
-
/// </summary>
-
public int CaptureWidth
-
{
-
get
-
{ return m_Width; }
-
-
set
-
{ m_Width = value; }
-
}
-
-
/// <summary>
-
/// The sequence number to start at for the frame number. OPTIONAL
-
/// </summary>
-
public ulong FrameNumber
-
{
-
get
-
{ return m_FrameNumber; }
-
-
set
-
{ m_FrameNumber = value; }
-
}
-
-
#endregion
-
-
#region Start and Stop Capture Functions
-
-
/// <summary>
-
/// Starts the video capture
-
/// </summary>
-
/// <param name="FrameNumber">the frame number to start at.
-
/// Set to 0 to let the control allocate the frame number</param>
-
public void Start(ulong FrameNum)
-
{
-
try
-
{
-
// for safety, call stop, just in case we are already running
-
this.Stop();
-
-
// setup a capture window
-
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, m_Width, m_Height, this.Handle.ToInt32(), 0);
-
-
// connect to the capture device
-
Application.DoEvents();
-
SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);
-
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0);
-
-
// set the frame number
-
m_FrameNumber = FrameNum;
-
-
// set the timer information
-
this.timer1.Interval = m_TimeToCapture_milliseconds;
-
bStopped = false;
-
this.timer1.Start();
-
}
-
-
catch (Exception excep)
-
{
-
MessageBox.Show("An error ocurred while starting the video capture. Check that your webcamera is connected properly and turned on.\r\n\n" + excep.Message);
-
this.Stop();
-
}
-
}
-
-
/// <summary>
-
/// Stops the video capture
-
/// </summary>
-
public void Stop()
-
{
-
try
-
{
-
// stop the timer
-
bStopped = true;
-
this.timer1.Stop();
-
-
// disconnect from the video source
-
Application.DoEvents();
-
SendMessage(mCapHwnd, WM_CAP_DISCONNECT, 0, 0);
-
}
-
-
catch (Exception excep)
-
{ // don't raise an error here.
-
}
-
-
}
-
-
#endregion
-
-
#region Video Capture Code
-
-
/// <summary>
-
/// Capture the next frame from the video feed
-
/// </summary>
-
private void timer1_Tick(object sender, System.EventArgs e)
-
{
-
try
-
{
-
// pause the timer
-
this.timer1.Stop();
-
-
// get the next frame;
-
SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);
-
-
// copy the frame to the clipboard
-
SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);
-
-
// paste the frame into the event args image
-
if (ImageCaptured != null)
-
{
-
// get from the clipboard
-
tempObj = Clipboard.GetDataObject();
-
tempImg = (System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);
-
-
/*
-
* For some reason, the API is not resizing the video
-
* feed to the width and height provided when the video
-
* feed was started, so we must resize the image here
-
*/
-
x.WebCamImage = tempImg.GetThumbnailImage(m_Width, m_Height, null, System.IntPtr.Zero);
-
-
// raise the event
-
this.ImageCaptured(this, x);
-
}
-
-
// restart the timer
-
Application.DoEvents();
-
if (!bStopped)
-
this.timer1.Start();
-
}
-
-
catch (Exception excep)
-
{
-
MessageBox.Show("An error ocurred while capturing the video image. The video capture will now be terminated.\r\n\n" + excep.Message);
-
this.Stop(); // stop the process
-
}
-
}
-
-
#endregion
-
-
private void WebCamCapture_Load(object sender, System.EventArgs e)
-
{
-
-
}
-
}
-
}
While searching for capturing video with a webcam I god the following code.It gives two errors.Says:The type or namespace name 'WebcamEventArgs' does not exit in the namespace 'WebCam_Capture' (are you missing an assembly reference?)
Can anybody help me?
Very interesting, does this only work for a particular cam type or for all of them that windows recognizes?
it looks very nice, If you guys can post detail info or article for that, will be great
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
Is there a Linux PHP module so that I can process web cam video with
Linux PHP from multiple USB ports? (I'm working on a video surveillance
idea since I found out that my office spent a whopping...
|
by: Ravi |
last post by:
Hi,
Im trying to develop a Visual C# .NET app. that uses DirectShow filters to capture video from camera source. However, after going through a series of articles, I've seen that DirectShow is not...
|
by: Lonewolf |
last post by:
Hi everyone, pls forgive me for my lack of knowledge and skills if my
question sounds very stupid. I am trying to implement a video conferencing
software and I am currently looking at a few set of...
|
by: tom |
last post by:
I need a C#, peer-to-peer solution for streaming video from a webcam on one box to a client application on the other box. Can someone please help me with this? I can read video from a webcam easy...
|
by: dicky2283 |
last post by:
windows development community please help me
im deepak roy , doing my final year undergrad in computer science....
im doing a project - Motion detection and Tracking in vc++( video for...
|
by: Suramya |
last post by:
Hi Friends,
I like to record a video file from remote client machine's webcam(from
browser) to the server machine (where IIS is running).
I could see an example of video recording for windows...
|
by: Stampede |
last post by:
Hi guys & girls,
I would like to write some kind of "Head-Tracking-Software", which uses a
WebCam to react to the movement of the head of the person sitting in front of
the monitor.
I searched...
|
by: Ivan Sammut |
last post by:
Hi,
I am using DirectShow to capture video from a webcam, but I need an mpeg
encoder which can save to a file. Anyone has any idea where I can get this
kind of filter or any link to an example
...
|
by: senthil |
last post by:
How to capture video stream from webcam in server and display it to client
browser.This has to be done on webform using asp.net(vb.net).i have seen lot
of samples for windows form it is not...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |