Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,please help me ,i have used directx,but i cannot know how to preview webcam in my form.
Posted
Updated 8-Jan-13 19:22pm
v3
Comments
Christian Graus 9-Jan-13 0:31am    
Try posting code to help us understand what you want
Christian Graus 9-Jan-13 0:31am    
If you just mean your local web cam, there's tons of articles on this site. If you mean one over the web, there's probably still articles you can use
Sergey Alexandrovich Kryukov 9-Jan-13 1:44am    
System.Windows.Forms? Tag it!
—SA

There is good number of ready-to-use solution published as CodeProject articles: http://www.codeproject.com/search.aspx?doctypeid=1&q=("Web+camera"+OR++Webcam)+"C%23"[^].

—SA
 
Share this answer
 
CSS
public DirectX.Capture.Filter Camera;

       public DirectX.Capture.Capture CaptureInfo;

       public DirectX.Capture.Filters CamContainer;

       Image captureImage;


C#
{
            CamContainer = new DirectX.Capture.Filters();


       try

       {

            int no_of_cam = CamContainer.VideoInputDevices.Count;



            for (int i = 0; i <no_of_cam; i++)

            {

                try

                {

                        // get the video input device

                        Camera = CamContainer.VideoInputDevices[i];



                        // initialize the Capture using the video input device

                        CaptureInfo = new DirectX.Capture.Capture(Camera, null);





                        // set the input video preview window

                        CaptureInfo.PreviewWindow = this.pictureBox1;



                        // Capturing complete event handler

                        CaptureInfo.FrameCaptureComplete += RefreshImage;



                        // Capture the frame from input device

                        CaptureInfo.CaptureFrame();



                        // if device found and initialize properly then exit without

                        // checking rest of input device

                        break;

                  }
                    catch (Exception ex) { }

            }

        }

        catch (Exception ex)

        {

                MessageBox.Show(this, "No Video Device Found", "Error");

         }

        }
        public void RefreshImage(PictureBox frame)
        {

            captureImage = frame.Image;


            this.pictureBox2.Image = captureImage;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            CaptureInfo.CaptureFrame();

        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900