In this post, we will see how to access a Camera using Silverlight 4.0 Out-Of-Browser and COM. To start with, let's first create a Silverlight application to access a camera, as shown below -
Once you create the project, choose ÁSP.NET Web Site' and Silverlight version 4.0. Now let's add a reference to the 'Microsoft.CSharp.dll' file. You can find this API here - 'C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client'.
Now let's design the Silverlight MainPage.xaml as shown below. Replace <Grid></Grid> with the following code -
In the XAML shown above, we are taking a Textbox to provide a name to our captured image and then will save it to our local drive, on the click event of a button.
Now let's write a code in our 'Access Camera' button click event, as shown below -
Now go to the Silverlight project properties. Right click Silverlight Project > Properties. Check the checkbox 'Enable Running Application out of the browser' and click on 'Out-Of-Browser Settings' button as shown below -
Now let's check the checkbox 'Require evaluated trust when running outside the browser' and compile your Silverlight application. Now hit 'F5' and you will see your application running out-of-browser. Click the button 'Access Camera' and you will see the Devices connect to your computer like Scanner or Camera etc. Choose Camera and you will see something similar -
Now select a picture and click on 'Get Picture' button which will save the selected picture with the name given in a Textbox on your local drive. In my case it is 'E:\' with the name 'Sample2.jpg' and this will look like the one shown below -
Note: Similarly you can also read Webcam Support in Silverlight 4 to capture Video
Download the Source Code
Will you give this article a +1 ? Thanks in advance