help! using webcam to take snapshots |
| |
|
|
|
New Poster Posts: 3 Topics: 2
|
|
|
March 29, 2010, 09:01:49 PM
|
|
I'm supposed to build a program that takes snapshots from time to time while the program is running using the webcam (with C#). In addition the snapshots should be saved in a folder on the comuter. I don't know how to do that but I managed to find a program that works. The only problem is that I can't see anything but a black background instead of the picture. Does anybody has a clue what maybe the problem? or does anybody can give me a link to a working program? or an explanation on how to communicate with the webcam and all.
I tried to run this program on another computer but still the problem persists.
Any help would be appreciated! Thanks
Here is the code:
using System; using System. Collections. Generic; using System. Linq; using System. Text; using WIA; using System. Net; using System. Windows. Forms;
namespace cp2 { class Snapper {
static void Main(String[] args) {
Device device = null;
DeviceManager manager = new DeviceManagerClass();
foreach (DeviceInfo info in manager. DeviceInfos) {
//Here there is only one device attached, for multi device
// we would need to have id of the desired device stored the properties and selected here by device id
if (info. Type == WiaDeviceType. VideoDeviceType) {
device = info. Connect();
Item item = device. ExecuteCommand(CommandID. wiaCommandTakePicture);
//pull the jpeg type id from registry. Keep this otherwise in properties
Microsoft. Win32. RegistryKey jpegKey = Microsoft. Win32. Registry. ClassesRoot. OpenSubKey(@"CLSID\{D2923B86-15F1-46FF-A19A-DE825F919576}\SupportedExtension\. jpg");
string jpegGuid = jpegKey. GetValue("FormatGUID") as string;
foreach (string format in item. Formats) {
if (format == jpegGuid) {
WIA. ImageFile imageFile= item. Transfer(format) as WIA. ImageFile;
Random random = new Random();
string imageFileName = @"c:\" + random. Next(99999) + ". jpeg";
imageFile. SaveFile(imageFileName);
Console. WriteLine("Pictured stored at: " + imageFileName);
} else {
Console. WriteLine("Unrecognized img format");
}
break;
}//end if
}//end foreach
}//end Main
}
} }
|
|
| |
|
|
|
New Poster Posts: 3 Topics: 2
|
|
|
April 01, 2010, 08:10:35 PM
|
|
Anybody?
|
|
| |
|
|
|
New Poster Posts: 1 Topics: 0
|
|
|
April 22, 2010, 04:29:31 AM
|
|
Does anybody has a clue what maybe the problem? or does anybody can give me a link to a working program? or an explanation on how to communicate with the webcam and all.
Seo in your hands
|
|
| |
|
|
|
Skilled Coder Posts: 103 Topics: 4
|
|
|
May 26, 2010, 04:09:28 PM
|
|
I'd ask for help on the C# boards if you haven't figured out the solution yet.
|
|
| |