




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
介绍与众不同 windows phone 7.5 (sdk 7.1) 之设备 硬件快门 自动对焦、自动对焦到指定的点 实时修改捕获到的视频帧 示例1、演示如何响应硬件快门HardwareShutter.xaml 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; using Microsoft.Devices;using System.Windows.Navigation;namespace Demo.Device.Camera public partial class HardwareShutter : PhoneApplicationPage private 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.xaml Focus.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.Camera public partial class Focus : PhoneApplicationPage private 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 = 自动对焦完成; ); else Deployment.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(); ); else this.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(); ); else this.Dispatcher.BeginInvoke(delegate() lblMsg.Text = 相机不支持自动对焦到指定的点; ); 3、演示如何实时修改捕获到的视频帧LiveAlter.xaml LiveAlter.xaml.cs/* * 演示如何实时处理摄像头捕获到的图像 * * PhotoCamera - 用于提供相机功能 * PreviewResolution - 捕获到的图像的当前的分辨率(返回 System.Windows.Size 类型的结构体,其包含 Width 和 Height 字段) * GetPreviewBufferArgb32(int pixelData) - 将当前捕获到的图像的 ARGB 数据复制到指定的缓冲区中 * * * 注: * Resolution 指的是相机设置的分辨率 * PreviewResolution 指的是系统针对显示设备缩放后的真实分辨率 * 因为通常相机能够拍摄大于设备显示器的分辨率的图像,所以实时显示摄像头捕获到的图像时,系统会对其分辨率进行优化,PreviewResolution 就是优化后的数据 */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.Threading;using System.Windows.Media.Imaging;using System.Windows.Navigation;namespace Demo.Device.Camera public partial class LiveAlter : PhoneApplicationPage private PhotoCamera _camera = new PhotoCamera(); / 用于显示处理后的图像 private WriteableBitmap _writeableBitmap; / 有信号 private static ManualResetEvent _manualReset = new ManualResetEvent(true); public LiveAlter() InitializeComponent(); protected override void OnNavigatedTo(NavigationEventArgs e) if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) / 实例化 PhotoCamera,并注册相关事件 _camera = new PhotoCamera(CameraType.Primary); _camera.Initialized += _camera_Initialized; videoBrush.SetSource(_camera); else this.Dispatcher.BeginInvoke(delegate() lblMsg.Text = 设备不支持主摄像头; ); protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) / 清理资源 if (_camera != null) _camera.Dispose(); _camera.Initialized -= _camera_Initialized; void _camera_Initialized(object sender, CameraOperationCompletedEventArgs e) / 新开线程去执行实时处理图片的任务 Thread thread = new Thread(CameraToGray); thread.Start(); this.Dispatcher.BeginInvoke(delegate() / 让 Image 显示 WriteableBitmap 中的内容 _writeableBitmap = new Writeab
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Unit 2 My school Lesson 3(教学设计)-2023-2024学年人教新起点版英语三年级下册
- 欣赏 《进行曲》教学设计-2025-2026学年小学音乐花城版五年级下册-花城版
- 塔吊安全员培训考试题目及答案解析
- 安全员B题库有多少原题及答案解析
- 预算入门基础知识培训课件
- 矿热电炉熔炼工岗前考核试卷及答案
- 湿法水刺非织造布制作工知识考核试卷及答案
- 熔析炉工转正考核试卷及答案
- 网络货运员岗位操作技能考核试卷及答案
- 建筑安全员培训题库及答案解析
- 1《我三十万大军胜利南渡长江》跨学科公开课一等奖创新教案统编版语文八年级上册
- 工程概算、预算、结算审核报告模板
- 2025至2030年中国不锈钢氢退丝行业投资前景及策略咨询报告
- 《民营经济促进法》全文学习解读
- 江西省防雷减灾白皮书 (2024年)
- 2025年新疆风力发电市场调查报告
- 面向新质生产力培育的科技成果转化策略与实践路径
- 2025年江西遂川县城发投资集团有限公司下属子公司招聘笔试参考题库含答案解析
- 布袋除尘器吊装方案
- 《人工智能:AIGC基础与应用》高职全套教学课件
- 装修公司全包装修合同
评论
0/150
提交评论