Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Capturing from Webcam without preview to the user

Capturing from Webcam without preview to the user

Scheduled Pinned Locked Moved C#
csharpwpfquestion
19 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pete OHanlon

    And how are you going to switch off the Webcam notification itself? You know, the light that appears on the camera when it's in use.

    S Offline
    S Offline
    Sultan Uz Zaman
    wrote on last edited by
    #8

    Since all the webcams are inside the cage the light can not be seen by the user.

    L P 2 Replies Last reply
    0
    • S Sultan Uz Zaman

      Since all the webcams are inside the cage the light can not be seen by the user.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #9

      Do take note that this might not be legal in some places :)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      S 1 Reply Last reply
      0
      • S Sultan Uz Zaman

        Since all the webcams are inside the cage the light can not be seen by the user.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #10

        Ultimately the webcam image is just a stream of bytes. That's all you need to know to work out the rest.

        S 2 Replies Last reply
        0
        • L Lost User

          Do take note that this might not be legal in some places :)

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

          S Offline
          S Offline
          Sultan Uz Zaman
          wrote on last edited by
          #11

          Don't worry, the DropBoxes are generally like this and it does not have any illegal elements. And by the way we are actually looking for something where there is no preview - just capture on demand. So, even if the user sees the light of the webcam it really doesn't matter because it actually strengthens his side in case of any dispute unless he claims anything useless (like claiming transaction without dropping the envelop).

          P 1 Reply Last reply
          0
          • P Pete OHanlon

            Ultimately the webcam image is just a stream of bytes. That's all you need to know to work out the rest.

            S Offline
            S Offline
            Sultan Uz Zaman
            wrote on last edited by
            #12

            Yes. But how do I do it without showing it on the image control?

            P 1 Reply Last reply
            0
            • S Sultan Uz Zaman

              Yes. But how do I do it without showing it on the image control?

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #13

              It's a stream of bytes. The image control just renders the bytes out - it's a convenience for you. You don't need it. Think about how you save a stream of bytes instead - that's the key. Forget that the Image Control ever existed.

              S 1 Reply Last reply
              0
              • P Pete OHanlon

                Ultimately the webcam image is just a stream of bytes. That's all you need to know to work out the rest.

                S Offline
                S Offline
                Sultan Uz Zaman
                wrote on last edited by
                #14

                Please find below the extarct of my application where the stream is stored in an image control named frameHolder and function SavePic grabs the current frame and save it to disk. frameHolder is shown on the Main Window. Making it invisible captures blank picture. MainWindow.xaml.cs void MainWindow_Loaded(object sender, RoutedEventArgs e) { LoaclWebCamsCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice); LocalWebCam = new VideoCaptureDevice(LoaclWebCamsCollection[0].MonikerString); LocalWebCam.DesiredFrameSize = new System.Drawing.Size(320, 240); //MessageBox.Show(LocalWebCam.DesiredFrameSize.ToString()); LocalWebCam.NewFrame += new NewFrameEventHandler(Cam_NewFrame); LocalWebCam.Start(); } void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs) { BitmapImage bi = new BitmapImage(); try { img = (Bitmap)eventArgs.Frame.Clone(); MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); Dispatcher.BeginInvoke(new ThreadStart(delegate { frameHolder.Source = bi; })); } catch (Exception ex) { MessageBox.Show(ex.Message, "NW CDM Test of Image Capture Failed"); } } Sultan Uz Zaman at 4 hrs ago Reply Modify the comment. Delete the comment. A button click event does the follwoing to save the pic: public static void SavePic(string imageFile) { //Cam_NewFrame(null,null); //image1.Source = frameHolder.Source; //Image frame = frameHolder.Cam_NewFrame(null,null); // Release any previous buffer MainWindow myWin = Application.Current.MainWindow as MainWindow; RenderTargetBitmap bitmap = new RenderTargetBitmap(320, 240, 96, 96, PixelFormats.Pbgra32); bitmap.Render(myWin.frameHolder); using (FileStream stream = File.Create(Global.xImageLocation+"\\"+imageFile)) // or .png { JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.QualityLevel = 90; encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(stream); } }

                1 Reply Last reply
                0
                • P Pete OHanlon

                  It's a stream of bytes. The image control just renders the bytes out - it's a convenience for you. You don't need it. Think about how you save a stream of bytes instead - that's the key. Forget that the Image Control ever existed.

                  S Offline
                  S Offline
                  Sultan Uz Zaman
                  wrote on last edited by
                  #15

                  This is where I failed to implement. Can you please share with me a few codes so I could understand the fact to store the stream anything other than the image control and grab the current from that variable?

                  P 1 Reply Last reply
                  0
                  • S Sultan Uz Zaman

                    This is where I failed to implement. Can you please share with me a few codes so I could understand the fact to store the stream anything other than the image control and grab the current from that variable?

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #16

                    You already have the code. All you need to do is use a FileStream instead of a MemoryStream to write the bytes out to a file.

                    S 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      You already have the code. All you need to do is use a FileStream instead of a MemoryStream to write the bytes out to a file.

                      S Offline
                      S Offline
                      Sultan Uz Zaman
                      wrote on last edited by
                      #17

                      Still cannot figure out. Please help the novice.

                      1 Reply Last reply
                      0
                      • S Sultan Uz Zaman

                        I would like to know if it is possible to develop an webcam application under WPF C# to capture webcam image and save it to disk without showing the preview (showing the content to the user)?

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #18

                        Didn't you just post a code dump about this the other day? If so, what part of the code doesn't work?

                        "I've seen more information on a frickin' sticky note!" - Dave Kreskowiak

                        1 Reply Last reply
                        0
                        • S Sultan Uz Zaman

                          Don't worry, the DropBoxes are generally like this and it does not have any illegal elements. And by the way we are actually looking for something where there is no preview - just capture on demand. So, even if the user sees the light of the webcam it really doesn't matter because it actually strengthens his side in case of any dispute unless he claims anything useless (like claiming transaction without dropping the envelop).

                          P Offline
                          P Offline
                          Paul Conrad
                          wrote on last edited by
                          #19

                          Eddy didn't mean illegal activity, but more of the legality of having a person on camera. You may need to have consent from the person or some notification that they are being filmed.

                          "I've seen more information on a frickin' sticky note!" - Dave Kreskowiak

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups