Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello my question is
click on start camera button video should be display & after that click on take picture button picture should be capture.But using this code error display on CaptureDeviceConfiguration.AllowedDeviceAccess;

I have made one application which is I have took two buttons,one image,one rectangle.
1)Start Camera
2)Take Picture

Click on Start Camera ->object allows you to capture audio and video from your computers webcam and microphone.
Click on Take Picture ->Picture should capture.

Code is as follows
Source Code
XML
<usercontrol x:class="WebCamera.MainPage" xmlns:x="#unknown">
    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" removed="White">
        <grid.rowdefinitions>
            <rowdefinition height="32" />
            <rowdefinition />
        </grid.rowdefinitions>
        <grid.columndefinitions>
            <columndefinition />
            <columndefinition />
        </grid.columndefinitions>
        <Button x:Name="startVideo" Grid.Row="0" Grid.Column="0" Content="Start Camera!" Click="startVideo_Click" />
        <Button x:Name="snap" Grid.Row="0" Grid.Column="1" Content="Take Picture!" Click="snap_Click" IsEnabled="False" />
        <Image x:Name="snapImage" Grid.Row="1" Grid.Column="1" />
        <rectangle x:name="video" grid.row="1" grid.column="0" />
    </grid>
</usercontrol>


UI Code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace WebCamera
{    public partial class MainPage : UserControl    
     {    private CaptureSource cs = null;
          public MainPage()        
          {
                InitializeComponent();
          }
        
          private void startVideo_Click(object sender, RoutedEventArgs e)        
          {            
                bool ok = CaptureDeviceConfiguration.AllowedDeviceAccess;
            
                if (!ok)            
                {                
                    ok = CaptureDeviceConfiguration.RequestDeviceAccess();            
                }
  
                if (ok)            
                {                
                    cs = new CaptureSource()                
                        {                    
                            VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()                
                        };

                    VideoBrush vidBrush = new VideoBrush();                
                    vidBrush.SetSource(cs);                
                    video.Fill = vidBrush;                
                    cs.Start();
                    snap.IsEnabled = true;            }        }
            private void snap_Click(object sender, RoutedEventArgs e)        
            {            
                cs.AsyncCaptureImage((bitmap) = >            
                {                
                    Dispatcher.BeginInvoke(() =>                
                    {                  
                        snapImage.Source = bitmap;                
                    });            
                });        
    }    
}}
Posted
v8
Comments
joshrduncan2012 15-Apr-13 9:41am    
not a question
Sergey Alexandrovich Kryukov 15-Apr-13 18:14pm    
The very last sentence is a question...
—SA
[no name] 15-Apr-13 17:07pm    
It's not showing up in intellisense because the editor does not know what CaptureSource is.
db7uk 15-Apr-13 18:08pm    
What version of SL are you using?
Inderveer kaur 16-Apr-13 1:30am    
SL 4 using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900