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 类来完成多媒体.然而,你懂的,要是多媒体文件比较大,转码时间会更长,有可能用户不会一眭停在当前应用界面上,或许会切换到其他应用程序,甚至 ...
随机推荐
- 猫学习IOS(四)UI半小时就搞定Tom猫
阿土 首先对影响 下载项目的源材料: Tom猫游戏代码iOS 素材http://blog.csdn.net/u013357243/article/details/44457357 效果图 以前风靡一时 ...
- 高仿淘宝送货地址暴走漫画系列(附demo)
演讲: 我是个程序员,一天我坐在路边一边喝水一边苦苦检查bug. 这时一个乞丐在我边上坐下了,開始要饭,我认为可怜.就给了他1块钱. 然后接着调试程序.他可能生意不好,就无聊的看看我在干什么.然后过了 ...
- 图片切割工具---产生多个div切割图片 采用for和一的二维阵列设置背景位置
照片库 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhb21vZ2c=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- HDD-FAT32 ZIP-FAT32
在使用U当家U盘启动盘制作工具的时候会看到一个模式的选项,模式分为HDD-FAT32和ZIP-FAT32两个常用的模式,其它的模式几乎用不到的.那么HDD-FAT32和ZIP-FAT32模式到底有什么 ...
- port大全及port关闭方法
在网络技术中,port(Port)大致有两种意思:一是物理意义上的port,比方,ADSL Modem.集线器.交换机.路由器用于连接其它网络设备的接口,如RJ-45port.SCport等等.二是逻 ...
- ssh: connect to host github.com port 22: Connection refused
假设git例如,下面的问题时,远程推送: [fulinux@ubuntu learngit]$ git push -u origin master ssh: connect to host githu ...
- java这些东西发展(1)-------大约ORA00604和ORA12705
******************************有关myEclipse和oracle在连接发生的一个问题********************************* 用户界面显示的评 ...
- socket示例代码演示程序(螺纹)
client码,如以下: import java.io.*; import java.net.*; public class DailyAdviceClient { public void go(){ ...
- POJ 3934 Queue(DP)
Queue Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the di ...
- log4j与commons-logging,slf4j的关系(转)
前面有一篇日志中简单的介绍了 log4j,同时也介绍了它与commons-logging的关系,但是突然冒出来一个slf4j,并且slf4j有取代commons-logging的趋势,所以,我们可以推 ...