Page 1 of 1

Capture Images/Video from webcam

Posted: Wed May 02, 2012 12:49 am
by CodenStuff
Capturing images or video from a webcam on Windows 8 has been made really simple and doesnt require any long complicated code to achieve.

This will allow you to capture an image or video from the devices webcam.

Capture an image:
Code: Select all
Dim CameraDialog = New CameraCaptureUI()
            Dim AspectRatio = New Size(16, 9)
            CameraDialog.PhotoSettings.CroppedAspectRatio = AspectRatio
            Dim CapturedImage = Await CameraDialog.CaptureFileAsync(CameraCaptureUIMode.Photo)
            Dim BitmapImage = New BitmapImage()
            Dim Filestream As IRandomAccessStream = Await CapturedImage.OpenAsync(Windows.Storage.FileAccessMode.Read)
            BitmapImage.SetSource(Filestream)
            PicBox.Source = BitmapImage
Change "PicBox" to the control you wish to display the captured image inside.
You need to enable 'Webcam' in the app capabilities settings.

Capture a video:
Code: Select all
Dim CameraDialog = New CameraCaptureUI()
            CameraDialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4
            Dim CapturedVideo = Await CameraDialog.CaptureFileAsync(CameraCaptureUIMode.Video)
            Dim Filestream As IRandomAccessStream = Await CapturedVideo.OpenAsync(Windows.Storage.FileAccessMode.Read)
            VidBox.SetSource(Filestream, "video/mp4")
Change "VidBox" to the control you wish to display the captured video inside (Media Element).
You need to enable 'Webcam' and 'Microphone' in the app capabilities settings.

Re: Capture Images/Video from webcam

Posted: Wed May 02, 2012 6:12 am
by MrAksel
Nice tutorial, but I'm looking for webcam streaming code for win 7 not 8 :)