Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

(译)Nokia Imaging SDK — 捕获高像素照片

From Wiki
Jump to: navigation, search

本文为翻译,原文链接在底部

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
Article Metadata

测试基于
SDK: Windows Phone 8.0 SDK, Nokia Imaging SDK Beta 1

兼容于
文章
段博琼 在 11 Oct 2013 创建
最后由 hamishwillee 在 17 Oct 2013 编辑

Contents

简介

可以使用Windows.Phone.Media.Capture.PhotoCaptureDevice 进行高像素图片的捕获(需要自己画视图界面,因为该平台的PhotoChooserTask API 不支持捕获高像素的功能),并且需要使用预定义像素分辨率手动设置捕获的像素。需要注意的额外的像素是没有从 PhotoCaptureDevice 类的获取 手机支持分辨率的静态方法 IReadOnlyList<Size> GetAvailabeCaptureResolutions() 方法中检索到的。还有就是为了让 PhotoCaptureDevice 正常工 作ID_CAP_ISV_CAMERA功能声明需要添加到清单文件WMAppManifest.xml

下面是可以手动获取的支持高分辨率的设备型号

手机型号 手动配置高像素的选项
RM-875, RM-876, RM-877 7712x4352 (16:9), 7136x5360 (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(7712, 4352); // 16:9 ratio
//captureResolution = new Windows.Foundation.Size(7136, 5360); // 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(1);
sequence.Frames[0].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

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 17 October 2013, at 00:43.
221 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×