• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2026 Replies
  • 331 Replies
    1928 Replies

Capture Images/Video from webcam

User avatar
CodenStuff
Site Admin
Posts: 4387

Capture Images/Video from webcam

Wed May 02, 2012 1: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:

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
Posts: 1758

Re: Capture Images/Video from webcam

Wed May 02, 2012 7:12 am

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

Post Reply

Return to “Visual Basic”