|
点击启用摄像头按钮后,Silverlight会提示用户是否允许应用程序访问你的本机视频设备。 ![]()
用户选择是后,用户的视频内容就会立刻显示在Border的VideoBrush区域内,是不是很容易呢。 ![]() ![]() 启用前 启用后 Silverlight 4.0不但支持视频设备的显示,同时结合控件的截图功能,可以很方便的得到用户的照片,接下来加入截图代码。 XAML: 1 <StackPanel x:Name="LayoutRoot">
2 <Border Height="350" x:Name="myBorder" CornerRadius="5" 3 BorderBrush="Gray" BorderThickness="3"> 4 <Border.Background> 5 <VideoBrush x:Name="myVideoBrush"/> 6 </Border.Background> 7 </Border> 8 <StackPanel x:Name="tsp" Orientation="Horizontal" 9 Height="100"></StackPanel> 10 <StackPanel Orientation="Horizontal" Height="30" 11 HorizontalAlignment="Center"> 12 <Button x:Name="btnCam" HorizontalAlignment="Right" 13 VerticalAlignment="Bottom" 14 Width="120" Height="30" 15 Content="启动摄像头"/> 16 <Button x:Name="btnCrop" HorizontalAlignment="Right" 17 VerticalAlignment="Bottom" 18 Width="120" Height="30" 19 Content="视频截图"/> 20 </StackPanel> 21 </StackPanel> C#: 1 void CropVideo()
2 { 3 //创建可写入位图对象 4 WriteableBitmap wBitmap = new WriteableBitmap(myBorder, new MatrixTransform()); 5 //创建一个图像 6 Image img = new Image(); 7 img.Width = 100; 8 img.Margin = new Thickness(2); 9 //将wBitmap做为图像源 10 img.Source = wBitmap; 11 //将图像添加到WrapPanel控件 12 tsp.Children.Add(img); 13 } 运行结果:
![]() 通过这种方式可以很方便的实现用户头像的上传,是不是很方便呢。 |









骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价