CameraCaptureUI樣本這個樣本示範了如何使用Windows.Media.Capture。 CameraCaptureUI API,這將顯示一個UI用於捕獲全屏照片或視頻。 async void Scenario1Button_Click(object sender, RoutedEventArgs e)
{
try
{
CameraCaptureUI dialog = new CameraCaptureUI();
Size aspectRatio = new Size(16, 9);
dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;
StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null)
{
Scenario1OutputText.Text = "";
BitmapImage bitmapImage = new BitmapImage();
using(IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
bitmapImage.SetSource(fileStream);
}
Scenario1Image.Source = bitmapImage;
Scenario1ResetButton.Visibility = Visibility.Visible;
photoFile = file.Path;
}
else
{
Scenario1OutputText.Text = "No photo captured.";
}
}
catch (Exception ex)
{
Scenario1OutputText.Text = ex.Message;
}
}
完整樣本:/Files/risk/windows8/相機和UI相機Sample.rar