Silverlight WebCam Application in VB.NET
In this article you will see how to create an simple Silverlight WebCam Application.
Silverlight WebCam: One of the new features in Silverlight 4 that I'm excited about is the support for webcams and microphones. There are several ways to interact with the WebCam, but i'll start with the most simple. I've written a simple demo that you can download here that will let you start the WebCam, take a snapshot from the WebCam and save it out as an image:
Below given example is a simple Webcam application, it could be expanded to do more as the CaptureSource can be used to take screenshots from the Webcam using the "AsyncCaptureImage" method.
Example of Silverlight WebCam
<UserControl x:Class="SilverlightApplication8.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="Click" Height="23" HorizontalAlignment="Left" Margin="26,12,0,0"Name="Button1"
VerticalAlignment="Top" Width="345" />
<Rectangle Height="257" VerticalAlignment="Top" Margin="12,41,12,0">
<Rectangle.Fill>
<VideoBrush x:Name="Display" Stretch="Uniform"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</UserControl>
//MainPage.xaml.vb Code
Partial Public Class MainPage
Inherits UserControl
Private Source As New CaptureSource
Public Sub New()
InitializeComponent()
Source.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
Display.SetSource(Source)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.Windows.RoutedEventArgs) Handles Button1.Click
If CaptureDeviceConfiguration.AllowedDeviceAccess OrCaptureDeviceConfiguration.RequestDeviceAccess() Then
If Source.State = CaptureState.Stopped Then
Source.Start()
Else
Source.Stop()
End If
End If
End Sub
End Class
Output Window
Conclusion
Hope this article would help you to understand how to create an simple Silverlight WebCam Application.