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

简介: 原文:Windows Phone 8.1 多媒体(1):相片Windows Phone 8.1 多媒体(1):相片 Windows Phone 8.1 多媒体(2):视频 Windows Phone 8.1 多媒体(3):音乐     (1)拍摄相片 1)CaptureElement CaptureElement 是放在应用界面上预览拍照的控件:   2)MediaCapture MediaCapture 是控制拍摄的重要类。
原文: 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 = 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;
}

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

目录
相关文章
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1251 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
|
XML 开发框架 前端开发
Windows Phone快速入门需掌握哪些能力
在此之前,先普及下Windows Phone的概念和开发工具的介绍。 Windows Phone是微软公司开发的手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。2012年6月21日,微软正式发布Windows Phone 8,采用和Windows 8相同的Windows NT内核,同时也针对市场的Windows Phone 7.5发布Windows Phone 7.8。
135 0
Windows Phone快速入门需掌握哪些能力
|
编解码 前端开发 JavaScript
Windows Phone 下开发 LBS 应用
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
162 0
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
230 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载