与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)

上传人:mg****85 文档编号:35596829 上传时间:2018-03-17 格式:DOC 页数:14 大小:125KB
返回 下载 相关 举报
与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)_第1页
第1页 / 共14页
与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)_第2页
第2页 / 共14页
与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)_第3页
第3页 / 共14页
与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)_第4页
第4页 / 共14页
与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)》由会员分享,可在线阅读,更多相关《与众不同 windows phone (22) - device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)(14页珍藏版)》请在金锄头文库上搜索。

1、介绍与众不同 windows phone 7.5 (sdk 7.1) 之设备硬件快门 自动对焦、自动对焦到指定的点 实时修改捕获到的视频帧 示例1、演示如何响应硬件快门HardwareShutter.xamlhttp:/ HardwareShutter.xaml.cs/* 演示如何捕获相机的硬件快门的相关事件* * CameraButtons.ShutterKeyHalfPressed - 硬件快门半按压时所触发的事件* CameraButtons.ShutterKeyPressed - 硬件快门全按压时所触发的事件* CameraButtons.ShutterKeyReleased - 硬件

2、快门被释放时所触发的事件* * * 注:无论是拍照模式还是摄像模式,只有在摄像头工作起来的时候,系统才能响应硬件快门的相关事件*/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.Windo

3、ws.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;http:/ using Microsoft.Devices;using System.Windows.Navigation;namespace Demo.Device.Camerapublic partial class HardwareShutter : PhoneApplicationPageprivate PhotoCamera _camera;public HardwareShutter()InitializeComponent(

4、);protected override void OnNavigatedTo(NavigationEventArgs e)if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary)_camera = new PhotoCamera(CameraType.Primary);/ 注册硬件快门的相关事件CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;CameraButtons.ShutterKeyPressed += CameraButton

5、s_ShutterKeyPressed;CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased;/ 相机模式下,必须将捕获到的信息输出到 UI 上,系统才能响应硬件快门的事件(同理,摄像模式下,必须调用了 CaptureSource.Start() 之后系统才能响应硬件快门的事件)videoBrush.SetSource(_camera);protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)/ 清理相关资源CameraButto

6、ns.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed;CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed;CameraButtons.ShutterKeyReleased -= CameraButtons_ShutterKeyReleased;void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)lblMsg.Text = “快门半按压“;void Camer

7、aButtons_ShutterKeyPressed(object sender, EventArgs e)lblMsg.Text = “快门全按压“;void CameraButtons_ShutterKeyReleased(object sender, EventArgs e)lblMsg.Text = “快门被释放“;2、演示如何自动对焦,以及如何自动对焦到指定的点Focus.xamlFocus.xaml.cs/* 演示如何自动对焦,以及如何自动对焦到指定的点* * PhotoCamera - 用于提供相机功能* Focus() - 让相机自动对焦* FocusAtPoint(doubl

8、e x, double y) - 自动对焦到取景器上指定的点* x, y - 取景器上需要对焦的点的坐标,取景器左上角坐标为 0,0,取景器右下角坐标为 1,1* AutoFocusCompleted - 自动对焦完成后所触发的事件(事件参数为 CameraOperationCompletedEventArgs 类型)* * * CameraOperationCompletedEventArgs* Succeeded - 操作是否成功* Exception - 异常信息*/using System;using System.Collections.Generic;using System.Li

9、nq;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.Nav

10、igation;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 =

11、new PhotoCamera(CameraType.Primary);_camera.AutoFocusCompleted += _camera_AutoFocusCompleted;/ 在 VideoBrush 上显示摄像头捕获到的实时信息videoBrush.SetSource(_camera);protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)/ 清理相关资源_camera.AutoFocusCompleted -= _camera_AutoFocusCompleted;void _camera_A

12、utoFocusCompleted(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, RoutedEventArg

13、s 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, S

14、ystem.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 /

15、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.BeginIn

16、voke(delegate()lblMsg.Text = “自动对焦到指定的点失败:“ + ex.ToString(););elsethis.Dispatcher.BeginInvoke(delegate()lblMsg.Text = “相机不支持自动对焦到指定的点“;);3、演示如何实时修改捕获到的视频帧LiveAlter.xamlLiveAlter.xaml.cs/* 演示如何实时处理摄像头捕获到的图像* * PhotoCamera - 用于提供相机功能* PreviewResolution - 捕获到的图像的当前的分辨率(返回 System.Windows.Size 类型的结构体,其包含 Width 和 Height 字段)* Get

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号