[Windwos 8][Metro Style App] 開啟內建 CameraCaptureUI

  • 4058
  • 0

摘要:[Windwos 8][Metro Style App] 開啟內建 CameraCaptureUI

如何使用內建的照相機UI攝影跟拍照呢?只要呼叫  Windows.Media.Capture 中的 CameraCaptureUI,如此一來就可以使用 Windows 8 內建的 Camera 功能。 拍照或錄影完會回傳一個 StorageFile,這點跟Windows Phone 7有點類似,Windows Phone 7 則是回傳 Strema。


var dialog = new CameraCaptureUI();
StorageFile _Getfile = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

如果要開啟錄影呢?

 


dialog.CaptureFileAsync(CameraCaptureUIMode.Video);


 

當然也會有一起開啟的時候吧!

 


dialog.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo)

圖片的格式 .net 內建了三種 EnCodeing jpeg png 和 JpegXR 要怎麼設定呢? 如下:


CameraCaptureUI ccui = new CameraCaptureUI();
ccui.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
StorageFile _Getfile = await ccui.CaptureFileAsync(CameraCaptureUIMode.Photo);
Debug.WriteLine("filename : "+_Getfile.Name);

--> filename : picture005.png

 

當然錄影也提供了 WMV 跟 Mp4 兩種檔案格式了。


CameraCaptureUIVideoFormat.Mp4
CameraCaptureUIVideoFormat.Wmv

 

但是,可能會發生這種情況...原因是在 Package.appxmanifest 裡面的 Capabilities 需勾選 WebCam 選項才能讓APP 開始這項功能。

 

 

 

 

之後進入的 Camera 又會再出現一次詢問,此次的提示是針對第一次安裝你的APP 之 USER 所提示的。 如勾選 Block 則在你的APP裡面永遠不能再開啟照相功能了,除非...

 

 

到 Settings -> Premissions 中把WebCam 功能變成 ON,如此一來你的APP就能順利使用照相功能了。

 

我猜想這是微軟為了隱私權做的功能吧。