The program should read from a config file for it's device settings and
simply capture using DV format to a specified file. The client program will
tell it START with a file name to capture to and STOP.
The features in the AMCap program work perfectly and I'm able to capture
with it just fine.
Unfortunately it's in C++ which I'm unfamiliar with for the most part. I've
just started doing C# programming having come from the Delphi world.
Is it easy to convert AMCap to C#? Does anyone know of any Active-X or Com
controls that work to capture DV and can be called from C#? (I've tried
several that don't work)
For an experienced programmer, what type of charge would there be to convert
AMCap to work in C#?
Thanks,
Kevin
The simple answer is learn C++ if you really want to take advantage of
DirectShow.
"Kevin Tupper" <tuppe...@hotmail.com> wrote in message
news:uzEBuEgXCHA.1748@tkmsftngp09...
internal class DigitalCam : WebCam
{
private int hWnd = 0 ;
private Timer timer;
[DllImport("avicap32.dll")]
private static extern int
capCreateCaptureWindow(string a, int b, int c, int d, int
e, int f, int g, int h);
[DllImport("user32.dll")]
private static extern int SendMessage(int
hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll",
EntryPoint="SendMessageA")]
private static extern int SendMessageS(int
hWnd, int wMsg, int wParam, string lParam);
[DllImport("user32.dll")]
private static extern int GetDesktopWindow
();
[DllImport("user32.dll")]
private static extern int DestroyWindow
(int hWnd);
public void StartPreview(int handle)
{
int hWnd = capCreateCaptureWindow
("Analog Cam", (int)
VideoConstants.ws_child,0,0,320,240,handle,0);
if (hWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");
int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_driver_connect,1,0);
if (temp == 0)
throw new
ApplicationException("Error connecting to driver");
}
unsafe public void StartVideo()
{
int desktopWnd = 0;
desktopWnd = GetDesktopWindow();
CAPTUREPARAMS param;
if (desktopWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");
hWnd = capCreateCaptureWindow
("Analog Cam", (int)
VideoConstants.ws_child,0,0,0,0,desktopWnd,0);
if (hWnd == 0)
throw new
ApplicationException("Error getting Desktop Window");
int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
//Video AVI
param.fYield = 1;
int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;
param.fCaptureAudio = 0;
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);
int algo = sizeof(CAPTUREPARAMS);
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_set_previewrate,4,0);
if (temp == 0)
throw new
ApplicationException("Error Setting Preview Rate");
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_driver_connect,1,0);
if (temp == 0)
throw new
ApplicationException("Error connecting to driver");
}
unsafe public void SaveAvi(string name)
{
CAPTUREPARAMS param;
int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
param.fYield = 1;
int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;
param.fAbortLeftMouse=0;
param.fAbortRightMouse=0;
param.fCaptureAudio = 0;
param.fLimitEnabled=0;
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
temp = SendMessageS(hWnd,(int)
VideoConstants.WM_CAP_FILE_SET_CAPTURE_FILE,0,name);
if (temp == 0)
throw new
ApplicationException("Error setting file name");
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq,0,0);
if (temp == 0)
throw new
ApplicationException("Error saving avi to disk");
}
unsafe public void SaveAvi(string name,
int seconds, object state)
{
CAPTUREPARAMS param;
int temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_GET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
param.fYield = 1;
int totalFrame = 25;
param.dwRequestMicroSecPerFrame=
1000000 / totalFrame;
param.fAbortLeftMouse=0;
param.fAbortRightMouse=0;
param.fCaptureAudio = 0;
param.fLimitEnabled=1;
param.wTimeLimit=(uint)seconds;
temp = SendMessage(hWnd,(int)
VideoConstants.WM_CAP_SET_SEQUENCE_SETUP,sizeof
(CAPTUREPARAMS),(int)¶m);
temp = SendMessageS(hWnd,(int)
VideoConstants.WM_CAP_FILE_SET_CAPTURE_FILE,0,name);
if (temp == 0)
throw new
ApplicationException("Error setting file name");
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq,0,0);
timer = new Timer(new TimerCallback
(myStopAvi),state,seconds*1000,Timeout.Infinite);
/*if (temp == 0)
throw new
ApplicationException("Error saving avi to disk");*/
}
private void myStopAvi(object state)
{
Hashtable table = state as
Hashtable;
lock(table)
{
table["Flag"] = false;
}
}
public void StopAvi()
{
int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_stop,0,0);
temp = SendMessage(hWnd,(int)
VideoConstants.wm_cab_cap_seq_nofile,0,0);
}
public void CloseVideo()
{
int temp = SendMessage(hWnd, (int)
VideoConstants.wm_cap_driver_disconnect, 0, 0);
temp = DestroyWindow (hWnd);
}
public byte[] GrabFrame(int width, int
height, int resolution)
{
//int temp = SendMessage(hWnd,(int)
VideoConstants.wm_cap_grab_frame,0,0);
int temp = SendMessageS(hWnd,(int)
VideoConstants.wm_cab_grab_frame_nonstop,0,"smartpicture.bm
p");
if (temp == 0)
{
throw new
ApplicationException("Error in Grab frame no stop");
}
if (temp == 0)
throw new
ApplicationException("Error Setting Grab Frame");
temp = SendMessageS(hWnd,(int)
VideoConstants.wm_cap_file_savedib,0,"smartpicture.bmp");
if (temp == 0)
{
throw new
ApplicationException("Error saving bitmap to disk");
}
FileStream f = new FileStream
("smartpicture.bmp", FileMode.OpenOrCreate);
byte [] buffer = new byte
[f.Length];
f.Read(buffer,0,buffer.Length);
f.Close();
return buffer;
}
}
}
>-----Original Message-----
>Message unavailable
Ever thought of using DirectShow? And using the COM interface to it? Once
you want to make a little more than what you do (for example adding other
filters etc.) ou are in for a nasty surprise.
--
Regards
Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
"Claudio Serrano" <claudio...@hotmail.com> wrote in message
news:1cd201c25f27$a2d4e620$36ef2ecf@tkmsftngxa12...