Silverlight访问摄像头和麦克风(1)客户端视听

silverlight4提供了摄像头机麦克风访问的API,尝试了一下,还不错。现在将简单的程序记录一下

sl前台呢,有两个控件,一个是用于显示摄像头捕捉到的内容,另一个是个按钮用来启动摄像头。

 代码

< Rectangle Height ="169" HorizontalAlignment ="Left" Margin ="37,21,0,0" Name ="rectangle1" Stroke ="Black" StrokeThickness ="1" VerticalAlignment ="Top" Width ="236"   />  
    
< Button Content ="Button" Height ="23" HorizontalAlignment ="Left" Margin ="120,196,0,0" Name ="button1" VerticalAlignment ="Top" Width ="75" Click ="button1_Click"   />

 后台呢,是给摄像头的内容传递到rectangle的方法。

 代码

CaptureSource source =   new CaptureSource(); 
           
if (source !=   null
            { 
                source.Stop(); 

                source.VideoCaptureDevice
= CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); 
                VideoBrush vidBrush
=   new VideoBrush(); 
                vidBrush.SetSource(source); 
               
this .rectangle1.Fill = vidBrush; 
               
if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) 
                { 
                    source.Start(); 
                } 
            }

使用模拟摄像头做的效果 

  

还可以截图等等。

非常简单,哈哈。

下一次将会对这个视频进行传输,完成视频对话的过程。

你可能感兴趣的:(职场,silverlight,audio,休闲,CAM)