Capture Images/Video from webcam

Visual Basic tutorials for UWP apps.
2 posts Page 1 of 1
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Capture Images/Video from webcam
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.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Nice tutorial, but I'm looking for webcam streaming code for win 7 not 8 :)
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
2 posts Page 1 of 1
Return to “Visual Basic”