资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
介绍与众不同 windows phone 7.5 (sdk 7.1) 之设备硬件快门 自动对焦、自动对焦到指定的点 实时修改捕获到的视频帧 示例1、演示如何响应硬件快门HardwareShutter.xamlhttp:/sucai.qqq80.com HardwareShutter.xaml.cs/* 演示如何捕获相机的硬件快门的相关事件* * CameraButtons.ShutterKeyHalfPressed - 硬件快门半按压时所触发的事件* CameraButtons.ShutterKeyPressed - 硬件快门全按压时所触发的事件* CameraButtons.ShutterKeyReleased - 硬件快门被释放时所触发的事件* * * 注:无论是拍照模式还是摄像模式,只有在摄像头工作起来的时候,系统才能响应硬件快门的相关事件*/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 Microsoft.Phone.Controls;http:/www.qinglvfenzu.com using Microsoft.Devices;using System.Windows.Navigation;namespace Demo.Device.Camerapublic partial class HardwareShutter : PhoneApplicationPageprivate PhotoCamera _camera;public HardwareShutter()InitializeComponent();protected override void OnNavigatedTo(NavigationEventArgs e)if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary)_camera = new PhotoCamera(CameraType.Primary);/ 注册硬件快门的相关事件CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased;/ 相机模式下,必须将捕获到的信息输出到 UI 上,系统才能响应硬件快门的事件(同理,摄像模式下,必须调用了 CaptureSource.Start() 之后系统才能响应硬件快门的事件)videoBrush.SetSource(_camera);protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)/ 清理相关资源CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed;CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed;CameraButtons.ShutterKeyReleased -= CameraButtons_ShutterKeyReleased;void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)lblMsg.Text = “快门半按压“;void CameraButtons_ShutterKeyPressed(object sender, EventArgs e)lblMsg.Text = “快门全按压“;void CameraButtons_ShutterKeyReleased(object sender, EventArgs e)lblMsg.Text = “快门被释放“;2、演示如何自动对焦,以及如何自动对焦到指定的点Focus.xamlFocus.xaml.cs/* 演示如何自动对焦,以及如何自动对焦到指定的点* * PhotoCamera - 用于提供相机功能* Focus() - 让相机自动对焦* FocusAtPoint(double x, double y) - 自动对焦到取景器上指定的点* x, y - 取景器上需要对焦的点的坐标,取景器左上角坐标为 0,0,取景器右下角坐标为 1,1* AutoFocusCompleted - 自动对焦完成后所触发的事件(事件参数为 CameraOperationCompletedEventArgs 类型)* * * CameraOperationCompletedEventArgs* Succeeded - 操作是否成功* Exception - 异常信息*/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 Microsoft.Phone.Controls;using Microsoft.Devices;using System.Windows.Navigation;namespace Demo.Device.Camerapublic partial class Focus : PhoneApplicationPageprivate PhotoCamera _camera;public Focus()InitializeComponent();protected override void OnNavigatedTo(NavigationEventArgs e)if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary)/ 实例化 PhotoCamera,注册相关事件_camera = new PhotoCamera(CameraType.Primary);_camera.AutoFocusCompleted += _camera_AutoFocusCompleted;/ 在 VideoBrush 上显示摄像头捕获到的实时信息videoBrush.SetSource(_camera);protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)/ 清理相关资源_camera.AutoFocusCompleted -= _camera_AutoFocusCompleted;void _camera_AutoFocusCompleted(object sender, CameraOperationCompletedEventArgs e)if (e.Succeeded)Deployment.Current.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “自动对焦完成“;);elseDeployment.Current.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “自动对焦失败“;);private void btnFocus_Click(object sender, RoutedEventArgs e)if (_camera.IsFocusSupported = true)try/ 开始自动对焦_camera.Focus();lblMsg.Text = “开始自动对焦“;catch (Exception ex)this.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “自动对焦失败:“ + ex.ToString(););elsethis.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “相机不支持自动对焦“;);private void canvas_Tap(object sender, System.Windows.Input.GestureEventArgs e)if (_camera != null)if (_camera.IsFocusAtPointSupported = true)try/ 获取用户触摸的点相对于 canvas 的坐标Point tapLocation = e.GetPosition(canvas);/ 计算触摸点映射于取景器上的坐标(取景器左上角为 0,0,右下角为1,1)double focusXPercent = tapLocation.X / canvas.Width;double focusYPercent = tapLocation.Y / canvas.Height;/ 自动对焦到指定的点_camera.FocusAtPoint(focusXPercent, focusYPercent);this.Dispatcher.BeginInvoke(delegate()lblMsg.Text = String.Format(“自动对焦到指定的点0X:1:N22Y:3:N2“, System.Environment.NewLine, focusXPercent, System.Environment.NewLine, focusYPercent););catch (Exception ex)this.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “自动对焦到指定的点失败:“ + ex.ToString(););elsethis.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “相机不支持自动对焦到指定的点“;);3、演示如何实时修改捕获到的视频帧LiveAlter.xamlLiveAlter.xaml.cs/* 演示如何实时处理摄像头捕获到的图像* * PhotoCamera - 用于提供相机功能* PreviewResolution - 捕获到的图像的当前的分辨率(返回 System.Windows.Size 类型的结构体,其包含 Width 和 Height 字段)* Get
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号