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

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

原文: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;}

更多的使用方法可到諾基亞協助中心查看:連結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.