Capture Images/Video from webcam
Posted: Wed May 02, 2012 12:49 am
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:
You need to enable 'Webcam' in the app capabilities settings.
Capture a video:
You need to enable 'Webcam' and 'Microphone' in the app capabilities settings.
This will allow you to capture an image or video from the devices webcam.
Capture an image:
Code: Select all
Change "PicBox" to the control you wish to display the captured image inside. 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
You need to enable 'Webcam' in the app capabilities settings.
Capture a video:
Code: Select all
Change "VidBox" to the control you wish to display the captured video inside (Media Element).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")
You need to enable 'Webcam' and 'Microphone' in the app capabilities settings.