博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows Phone 8.1 多媒体(1):相片
阅读量:7191 次
发布时间:2019-06-29

本文共 2350 字,大约阅读时间需要 7 分钟。

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

 


 

(1)拍摄相片

1)CaptureElement

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

 

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
Initialize(){ photoCapture = new MediaCapture(); await photoCapture.InitializeAsync(); photoCapture.VideoDeviceController.PrimaryUse = CaptureUse.Photo; imgEncodingProperties = ImageEncodingProperties.CreateJpeg(); imgEncodingProperties.Width = 640; imgEncodingProperties.Height = 480; 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;}

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

转载于:https://www.cnblogs.com/xiaoshi3003/p/3784030.html

你可能感兴趣的文章
我的友情链接
查看>>
微信内部浏览器打开网页时提示外部浏览器打开遮罩升级版
查看>>
Go语言类型的本质
查看>>
界面主窗体,子窗体的InitializeComponent(构造函数)、Load事件执行顺序
查看>>
java导入导出Excel数据的要点记录
查看>>
汇编2——完整的例子集合
查看>>
TP缓存设计方案解析
查看>>
APIO2010 特别行动队
查看>>
Javascript语言精粹之Array常用方法分析
查看>>
屏蔽右键
查看>>
数值优化(三)
查看>>
连接池
查看>>
Retrofit 2.0使用
查看>>
win8 解析json数据模板 XMl解析数据
查看>>
Android原生代码与html5交互
查看>>
hibernate.cfg.xml配置
查看>>
将零散文件使用ICSharpCode.SharpZipLib压缩打包后一次性下载
查看>>
Python 爬取简单网页
查看>>
【机器学习】--xgboost初始之代码实现分类
查看>>
【强化学习篇】--强化学习从初识到应用
查看>>