Programming and Webmasters forum
HomeSearchRecent PostsLoginRegister Contact Us

Username  
Password
Announcing 14th Weekly Contest - From 25 July To 01 August.

Win every week on this forum.

Chek out How To Win?
 

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

help! using webcam to take snapshots

 
webmaster forum
silooz  Offline
Contest Points: 100
 
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

        }

    }
}
 
webmaster forum
silooz  Offline
Contest Points: 100
 
New Poster
Posts: 3
Topics: 2
April 01, 2010, 08:10:35 PM

Anybody?
 
webmaster forum
Contest Points: 100
 
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
 
webmaster forum
Jeremy  Offline
Contest Points: 100
 
Skilled Coder
Posts: 102
Topics: 4
WWW
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.

Second Home Mortgage
Private Student Loans
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC


Google visited last this page July 13, 2010, 05:08:39 AM

Valid XHTML 1.0 Transitional     Valid XHTML 1.0 Transitional