捕获高像素照片(updated)
可以使用Windows.Phone.Media.Capture.PhotoCaptureDevice 进行高像素图片的捕获(需要自己画视图界面,因为该平台的PhotoChooserTask API 不支持捕获高像素的功能),并且需要使用预定义像素分辨率手动设置捕获的像素。需要注意的额外的像素是没有从 PhotoCaptureDevice 类的获取手机支持分辨率的静态方法 IReadOnlyList<Size> GetAvailabeCaptureResolutions() 方法中检索到的。还有就是为了让 PhotoCaptureDevice 正常工作ID_CAP_ISV_CAMERA功能声明需要添加到清单文件WMAppManifest.xml
下面是可以手动获取的支持高分辨率的设备型号
手机型号 | 变体 | 手动配置高像素的选项 |
---|---|---|
Lumia 1020 | RM-875, RM-876, RM-877 | 7712x4352 (16:9), 7136x5360 (4:3) |
Lumia 1520 | RM-937, RM-938, RM-939 | 5376x3024 (16:9), 4992x3744 (4:3) |
为高像素拍摄初始化相机
下面的示例代码演示你如何在应用中创建简单的取景器,并且初始化高像素 photo capture。下面
的代码是使用 VideoBrush 作为 canvas 的背景:
- <!-- Simple viewfinder page -->
- <phone:PhoneApplicationPage x:Class="ViewfinderPage" ... >
- <Grid x:Name="LayoutRoot" Background="Transparent">
- <Grid x:Name="ContentPanel">
- <Canvas x:Name="Canvas" ... >
- <Canvas.Background>
- <VideoBrush x:Name="ViewfinderVideoBrush" Stretch="Uniform"/>
- </Canvas.Background>
- </Canvas>
- </Grid>
- </Grid>
- </phone:PhoneApplicationPage>
在相应的 C# 页面,向以往相同,先初始化 PhotoCaptureDevice,这里需要添加额外的代码检测
设备的型号,从而根据条件进行选择,并且在 IAsyncOperation<PhotoCaptureDevice> OpenAsync(CameraSensorLocation senor, Size initialRsolution) 方法中初始化高分辨率的尺寸。需要注意的是你只能每次使用一种分辨率捕获一张照片,所以如果你需要高像素的版本和低像素
的版本的图片,你可以先捕获一张高像素照片,然后对它进行操作,比如使用 Nokia Imaging SDK 对它进行压缩
尺寸来获得另一个版本的图片。
- using Microsoft.Devices;
- using Windows.Phone.Media.Capture;
- ...
- public partial class ViewfinderPage : PhoneApplicationPage
- {
- private const CameraSensorLocation SENSOR_LOCATION = CameraSensorLocation.Back;
- private PhotoCaptureDevice _device = null;
- private bool _focusing = false;
- private bool _capturing = false;
- ...
- ~ViewfinderPage()
- {
- if (_device != null)
- {
- UninitializeCamera();
- }
- }
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- if (_device == null)
- {
- InitializeCamera();
- }
- }
- protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
- {
- if ((_focusing || _capturing) && e.IsCancelable)
- {
- e.Cancel = true;
- }
- base.OnNavigatingFrom(e);
- }
- protected override void OnNavigatedFrom(NavigationEventArgs e)
- {
- base.OnNavigatedFrom(e);
- if (_device != null)
- {
- UninitializeCamera();
- }
- }
- /// <summary>
- /// Synchronously initialises the photo capture device for a high resolution photo capture.
- /// Viewfinder video stream is sent to a VideoBrush element called ViewfinderVideoBrush, and
- /// device hardware capture key is wired to the CameraButtons_ShutterKeyHalfPressed and
- /// CameraButtons_ShutterKeyPressed methods.
- /// </summary>
- private void InitializeCamera()
- {
- Windows.Foundation.Size captureResolution;
- var deviceName = DeviceStatus.DeviceName;
- if (deviceName.Contains("RM-875") || deviceName.Contains("RM-876") || deviceName.Contains("RM-877"))
- {
- captureResolution = new Windows.Foundation.Size(, ); // 16:9 ratio
- //captureResolution = new Windows.Foundation.Size(7136, 5360); // 4:3 ratio
- }
- else if (deviceName.Contains("RM-937") || deviceName.Contains("RM-938") || deviceName.Contains("RM-939"))
- {
- captureResolution = new Windows.Foundation.Size(, ); // 16:9 ratio
- //captureResolution = new Windows.Foundation.Size(4992, 3744); // 4:3 ratio
- }
- else
- {
- captureResolution = PhotoCaptureDevice.GetAvailableCaptureResolutions(SENSOR_LOCATION).First();
- }
- var task = PhotoCaptureDevice.OpenAsync(SENSOR_LOCATION, captureResolution).AsTask();
- task.Wait();
- _device = task.Result;
- ViewfinderVideoBrush.SetSource(_device);
- if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION))
- {
- Microsoft.Devices.CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;
- }
- Microsoft.Devices.CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;
- ...
- }
- /// <summary>
- /// Uninitialises the photo capture device and unwires the device hardware capture keys.
- /// </summary>
- private void UninitializeCamera()
- {
- if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION))
- {
- Microsoft.Devices.CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed;
- }
- Microsoft.Devices.CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed;
- _device.Dispose();
- _device = null;
- }
- ...
- }
拍摄
现在设备的相机已经初始化完成了,设备的拍照按键可以是相机进行自动对焦,并且捕获一张高像素照片
- ...
- public partial class ViewfinderPage : PhoneApplicationPage
- {
- ...
- /// <summary>
- /// Asynchronously autofocuses the photo capture device.
- /// </summary>
- private async void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)
- {
- if (!_focusing && !_capturing)
- {
- _focusing = true;
- await _device.FocusAsync();
- _focusing = false;
- }
- }
- /// <summary>
- /// Asynchronously captures a frame for further usage.
- /// </summary>
- private async void CameraButtons_ShutterKeyPressed(object sender, EventArgs e)
- {
- if (!_focusing && !_capturing)
- {
- _capturing = true;
- var stream = new MemoryStream();
- try
- {
- var sequence = _device.CreateCaptureSequence();
- sequence.Frames[].CaptureStream = stream.AsOutputStream();
- await _device.PrepareCaptureSequenceAsync(sequence);
- await sequence.StartCaptureAsync();
- }
- catch (Exception ex)
- {
- stream.Close();
- }
- _capturing = false;
- if (stream.CanRead)
- {
- // We now have the captured image JPEG data in variable "stream" for further usage
- }
- }
- }
- ...
- }
获得一个全功能的“单击画面对焦”、“在捕获时冻结预览”,可以参考示例代码 Photo Inspector
Nokia WiKi 原文链接:http://developer.nokia.com/Resources/Library/Lumia/#!imaging/working-with-high-resolution-photos/capturing-high-resolution-photos.html
捕获高像素照片(updated)的更多相关文章
- Unity 3D 调用摄像头捕获照片 录像
1,要想调用摄像头首先要打开摄像头驱动,如果用户允许则可以使用. 2,定义WebCamTexture的变量用于捕获单张照片. 3,连续捕获须启用线程. 实现代码: using UnityEngine; ...
- 处理图片(updated)
高像素的图片,比如分辨率为 7712x4352 的照片,当加载到一个 bitmap 中时会占用相当大的内存. 每个像素会占用 4个字节的内存,所以当没有被压缩时,全部的图片会占用 12800万字节(约 ...
- HoloLens开发手记 - Unity之Locatable camera 使用相机
Enabling the capability for Photo Video Camera 启用相机能力 为了使用摄像头,我们必须启用WebCam能力. 在Unity中打开Player settin ...
- 快速构建Windows 8风格应用29-捕获图片与视频
原文:快速构建Windows 8风格应用29-捕获图片与视频 引言 本篇博文主要介绍Windows 8中相机的概念.捕获图片与视频的基本原理.如何实现捕获图片与视频.相机最佳实践. 一.相机 关于相机 ...
- UIImagePickerController 相关
UIImagePickerController是系统封装好的一个导航视图控制器,使用其开发者可以十分方便的进行相机相册相关功能的调用.UIImagePickerController继承于UINavig ...
- Android Intent 教程
原文:Android: Intents Tutorial 作者:Darryl Bayliss 译者:kmyhy 人不会漫无目的地瞎逛,他们所做的大部分事情--比方看电视.购物.编写下一个杀手级 app ...
- opencv python训练人脸识别
总计分为三个步骤 一.捕获人脸照片 二.对捕获的照片进行训练 三.加载训练的数据,识别 使用python3.6.8,opencv,numpy,pil 第一步:通过笔记本前置摄像头捕获脸部图片 将捕获的 ...
- 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频
[源码下载] 与众不同 windows phone (41) - 8.0 相机和照片: 通过 AudioVideoCaptureDevice 捕获视频和音频 作者:webabcd 介绍与众不同 win ...
- 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片
[源码下载] 与众不同 windows phone (42) - 8.0 相机和照片: 通过 PhotoCaptureDevice 捕获照片 作者:webabcd 介绍与众不同 windows pho ...
随机推荐
- [Todo]提升电商网站性能方面的一些资料材料
又到国庆,喷一喷12306.cn的技术架构 http://chengxu.org/p/369.html 其中用到了不少比较细节的优化技巧. 提到库存管理是电商非常难的地方.也讲了跟秒杀相关的一些内容.
- Dede(织梦) CMS SQL Injection Vulnerability
测试方法: @Sebug.net dis本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! # Dede Cms All Versions Sql Vulnerability ...
- 会话追踪(session tracking)
HTTP是一种无连接的协议,如果一个客户端只是单纯地请求一个文件(HTML或GIF),服务器端可以响应给客户端,并不需要知道一连串的请求是否来自于相同的客户端,而且也不需要担心客户端是否处在连接状态. ...
- 利用kettle中的JS来完成ETL数据校验
最近参与了一个信托行业的BI项目,由于信托业务系统设计的问题,很多都是用户手工录入的数据,也有一些是需要分析的但是用户没有录入的数据,针对这样的数据质量,我们就要在ETL抽取的过程中来对数据流进行校验 ...
- [RSpec] LEVEL 1: INTRODUCTION
Install RSpec: Describe Lets start writing a specification for the Tweet class. Write a describe blo ...
- HDU2089 ------不要62(数位dp)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 给你的webstorm添加快速生成注释得快捷键
打开File----setting-map-搜搜"fix doc"
- Cleaner ITweenPath Source
iTweenPath.cs [pyg language="csharp" s="monokai" ] //Slight additions for a clea ...
- NSURLConnection经常使用的代理方法
NSURLConnection的代理Protocol定义有三类:NSURLConnectionDelegate.NSURLConnectionDataDelegate和NSURLConnectionD ...
- Matlab interpgui
function interpgui(arg1,arg2) %INTERPGUI Behavior of interpolating functions. % Demonstrates interpo ...