Windows Phone 8.1 多媒体(1):相片
原文:Windows Phone 8.1 多媒体(1):相片
Windows Phone 8.1 多媒体(1):相片
(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):相片的更多相关文章
- Windows Phone 8.1 多媒体(3):音乐
原文:Windows Phone 8.1 多媒体(3):音乐 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...
- Windows Phone 8.1 多媒体(2):视频
原文:Windows Phone 8.1 多媒体(2):视频 Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone ...
- C# Winform使用Windows Media Player播放多媒体整理
一.简单使用示例步骤 1.添加Windows Media Player 组件当前是系统的 Com组件 工具箱>右键“选择项”>选择Com组件 2.控件拖拽到桌面,使用 private vo ...
- windows live writer插件说明文档(附录网盘地址)
百度云地址:http://pan.baidu.com/s/1hqnjzjY 1.Screen Capture tool 用于直接在WLWriter中进行截图的一个插件,要配合SnagIt 这个软件使用 ...
- Windows 8.1 Preview的新功能和新API
http://msdn.microsoft.com/en-us/library/windows/apps/bg182410 App打包 新的App程序包将使App的提交更简单.资源包可以让你提供附加的 ...
- 通过使用 NTLite 工具实现精简Windows系统
NTLite 是一款专业于Windows平台的系统精简工具,NTLite主要面对系统封装人员使用,比如各大下载站及GHO镜像下载站,Windows系统二次精简封装打包使用,NTLite可以对系统进行极 ...
- Windows高速定时器,多媒体定时器winmm.dll库的使用
项目里面用到的这些看起来名字高大上的定时器测试下来也是非常不准.看了源码发现也是用System.Timers.Timer或者用的是Thread休眠的方式来实现的.100毫秒就不准了.直到一番搜索,发现 ...
- Windows 常用运行库下载 (DirectX、VC++、.Net Framework等)
经常听到有朋友抱怨他的电脑运行软件或者游戏时提示缺少什么 d3dx9_xx.dll 或 msvcp71.dll.msvcr71.dll又或者是 .Net Framework 初始化之类的错误而无法正常 ...
- 【Win 10 应用开发】在后台进行多媒体转码
前面,老周给大伙儿讲了如何运用 MediaTranscoder 类来完成多媒体.然而,你懂的,要是多媒体文件比较大,转码时间会更长,有可能用户不会一眭停在当前应用界面上,或许会切换到其他应用程序,甚至 ...
随机推荐
- android:强大的图像下载和缓存库Picasso
1.Picasso一个简短的引论 Picasso它是Square该公司生产的一个强大的图像下载并缓存画廊.官方网站:http://square.github.io/picasso/ 仅仅须要一句代码就 ...
- POJ 3009-Curling 2.0(DFS)
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12158 Accepted: 5125 Desc ...
- Redis数据结构
Redis数据结构 Redis数据结构详解(一) 前言 Redis和Memcached最大的区别,Redis 除啦支持数据持久化之外,还支持更多的数据类型而不仅仅是简单key-value结构的数据 ...
- SDUT oj 3005 打怪升级(内存搜索)
当比赛一直纠缠骑2如何做一个非常大的数量,数组不开啊...后来他们发现自己很傻啊,该数不超过最大10什么,这个上限就是力量100什么.. .. 其它的就是记忆化搜索啊,还有就是加一点力量的瓶子当时就要 ...
- Ping azure
最近azure在虚拟机上打开(欧式世纪互联),这其实并不能ping虚拟机! 查了一下资料,发现azure不支持被ping这个功能(貌似是不开放ICMP-in这个协议).有些用户跟客服问过这个问题,可是 ...
- 渲染优化 之fixed与返回顶部 以及开启GPU Hack
fixed元素,常见网站右侧出现一个返回顶部的按钮,滚动的时候,会发现返回顶部这个区域在不停的进行重绘,而返回顶部是position:fixed定位的.这也解释了为什么fixed定位是最耗性能的属性之 ...
- MVC中的Views下面的视图放到Views文件夹外
实战:把ASP.NET MVC中的Views下面的视图放到Views文件夹外 园子里写的文章的都是把控制器从传统的项目中的Controllers拿出来单独放,但很少几乎没有把视图从Views拿出去 ...
- Forbidden You don't have permission to access / on this server.
原文:Forbidden You don't have permission to access / on this server. Forbidden You don't have permissi ...
- CSDN博客ByeBye
情绪csdn定制博客博客是不够的,没有足够的光.对于我这种极简的人,不合适. 我们不打算更新的博客. 至http://blog.edagarli.com/ 版权声明:本文博主原创文章.博客,未经同意不 ...
- 文件类似的推理 -- 超级本征值(super feature)
基于内容的变长分块(CDC)技术,能够用来对文件进行变长分块.而后用来进行反复性检測,广泛用于去重系统中.后来又出现了对相似数据块进行delta压缩,进一步节省存储开销. 所以就须要一种高效 ...