原文:Windows Phone 8.1 多媒体(1):相片

Windows Phone 8.1 多媒体(1):相片

Windows Phone 8.1 多媒体(2):视频

Windows Phone 8.1 多媒体(3):音乐


(1)拍摄相片

1)CaptureElement

CaptureElement 是放在应用界面上预览拍照的控件:

<Grid>
<CaptureElement x:Name="capturePhotoElement"/>
</Grid> <Page.BottomAppBar>
<CommandBar>
<AppBarButton x:Name="btnCapturePhoto"
Icon="Camera" Label="Capture"
Click="btnCapturePhoto_Click"/>
</CommandBar>
</Page.BottomAppBar>

2)MediaCapture

MediaCapture 是控制拍摄的重要类。

首先初始化 MediaCapture,并将 CaptureElement 的 Source 设为 该 MediaCapture:

MediaCapture photoCapture;
ImageEncodingProperties imgEncodingProperties; protected override async void OnNavigatedTo(NavigationEventArgs e)
{
capturePhotoElement.Source = await Initialize(); await photoCapture.StartPreviewAsync();
} private async Task<MediaCapture> Initialize()
{
photoCapture = new MediaCapture();
await photoCapture.InitializeAsync(); photoCapture.VideoDeviceController.PrimaryUse = CaptureUse.Photo; imgEncodingProperties = ImageEncodingProperties.CreateJpeg();
imgEncodingProperties.Width = ;
imgEncodingProperties.Height = ; return photoCapture;
}

然后在按下某个按钮的时候完成拍摄:

private async void btnCapturePhoto_Click(object sender, RoutedEventArgs e)
{
var photo = await KnownFolders.PicturesLibrary.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName); await photoCapture.CapturePhotoToStorageFileAsync(imgEncodingProperties, photo);
}

也可以添加手机实体按键的事件:

HardwareButtons.CameraHalfPressed += HardwareButtons_CameraHalfPressed;

async void HardwareButtons_CameraHalfPressed(object sender, CameraEventArgs e)
{
await photoCapture.VideoDeviceController.FocusControl.FocusAsync();
}

最后记得在离开页面时释放 MediaCapture 资源:

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
if( photoCapture != null )
{
photoCapture.Dispose();
photoCapture = null;
}
}

(2)编辑相片

我在这里使用了 Nokia Imaging SDK 和 WritableBitmapEx 库,可在 Nuget 中搜索并安装。

注意要将配置管理器中的 CPU 改成 ARM,否则 Nokia Imaging SDK 将不可用。

使用方法非常简单,比如以下为一张图片添加滤镜:

WriteableBitmap originBitmap;
WriteableBitmap editedBitmap; private async void editButton_Click(object sender, RoutedEventArgs e)
{
var imageSource = new BitmapImageSource(originBitmap.AsBitmap()); using( var effect = new FilterEffect(imageSource) )
{
var filter = new AntiqueFilter(); effect.Filters = new[] { filter }; var renderer = new WriteableBitmapRenderer(effect, originBitmap);
editedBitmap = await renderer.RenderAsync(); editedBitmap.Invalidate();
} myImage.Source = editedBitmap;
}

更多的使用方法可到诺基亚帮助中心查看:链接

Windows Phone 8.1 多媒体(1):相片的更多相关文章

  1. Windows Phone 8.1 多媒体(3):音乐

    原文:Windows Phone 8.1 多媒体(3):音乐 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...

  2. Windows Phone 8.1 多媒体(2):视频

    原文:Windows Phone 8.1 多媒体(2):视频 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...

  3. C# Winform使用Windows Media Player播放多媒体整理

    一.简单使用示例步骤 1.添加Windows Media Player 组件当前是系统的 Com组件 工具箱>右键“选择项”>选择Com组件 2.控件拖拽到桌面,使用 private vo ...

  4. windows live writer插件说明文档(附录网盘地址)

    百度云地址:http://pan.baidu.com/s/1hqnjzjY 1.Screen Capture tool 用于直接在WLWriter中进行截图的一个插件,要配合SnagIt 这个软件使用 ...

  5. Windows 8.1 Preview的新功能和新API

    http://msdn.microsoft.com/en-us/library/windows/apps/bg182410 App打包 新的App程序包将使App的提交更简单.资源包可以让你提供附加的 ...

  6. 通过使用 NTLite 工具实现精简Windows系统

    NTLite 是一款专业于Windows平台的系统精简工具,NTLite主要面对系统封装人员使用,比如各大下载站及GHO镜像下载站,Windows系统二次精简封装打包使用,NTLite可以对系统进行极 ...

  7. Windows高速定时器,多媒体定时器winmm.dll库的使用

    项目里面用到的这些看起来名字高大上的定时器测试下来也是非常不准.看了源码发现也是用System.Timers.Timer或者用的是Thread休眠的方式来实现的.100毫秒就不准了.直到一番搜索,发现 ...

  8. Windows 常用运行库下载 (DirectX、VC++、.Net Framework等)

    经常听到有朋友抱怨他的电脑运行软件或者游戏时提示缺少什么 d3dx9_xx.dll 或 msvcp71.dll.msvcr71.dll又或者是 .Net Framework 初始化之类的错误而无法正常 ...

  9. 【Win 10 应用开发】在后台进行多媒体转码

    前面,老周给大伙儿讲了如何运用 MediaTranscoder 类来完成多媒体.然而,你懂的,要是多媒体文件比较大,转码时间会更长,有可能用户不会一眭停在当前应用界面上,或许会切换到其他应用程序,甚至 ...

随机推荐

  1. 在Linux终端下使用代理访问网络(转)

    最近,需要在linux环境下使用脚本进行一些网络访问(主要是HTTP请求与文件下载),于是查阅了一些关于代理的资料. 以下是尝试的几种代理设置方法,以供参考: 一.使用wget命令进行代理访问 wge ...

  2. Android设计模式(十)--生成器模式

    回头看自己写的东西,大概Android当自己控制的定义,编写代码适用性比较高.但是,看看没有什么技术含量,因此,当在学习设计模式,想想有些东西是否可以改善,例如: 自己定义Dialog是Android ...

  3. [LeetCode] Combinations [38]

    称号 Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exa ...

  4. sqlserver缓存程序-只能使用一次清除缓存计划

    plan cache非常大.将仅仅使用一次的缓存计划清除,而不用清除整个cache. declare @sid varbinary(64) declare cur01 cursor for selec ...

  5. OSChina 的URL类的源代码重写过程

    此代码是 oschina 到手柄形状像 http://www.oschina.net/p/tomcat 这种URL 此类已经废弃,改用 http://www.oschina.net/code/snip ...

  6. Android适配方案小结(一)

    相关计量单位介绍: px:是屏幕的像素点,不同设备显示的效果一样. in:英寸(1英寸等于2.54cm) mm:毫米 pt:磅, 1/72英寸 dp:device independent pixels ...

  7. Cache基础知识OR1200在ICache一个简短的引论

    以下摘录<步骤吓得核心--软-core处理器的室内设计与分析>一本书 12.1 Cache基本知识 12.1.1 Cache的作用 处理器的设计者通常会声称其设计的处理器一秒钟能做多少次乘 ...

  8. android 推断应用程序是系统程序还是用户程序

    直接上代码: AppInfo.java <span style="font-size:18px;">package com.example.packages; publ ...

  9. HTTP Cookie深入理解

    HTTP Cookie 概述:Cookie通常也叫做网站cookie,浏览器cookie或者http cookie,是保存在用户浏览器端的,并在发出http请求时会默认携带的一段文本片段.它可以用来做 ...

  10. 系统ls命令出现1;2cl;2cl;2cl;2c(转)

    1;2c after using cat or more on binary filesI noticed that if you use the hex 05 in a file and cat o ...