2015-07-11 49 views
0

我正在爲windows phone 8.1編程並使用MediaCapture(Windows.Media.Capture)構建了一個基本相機。 如何將焦點和閃光燈添加到相機?這是我當前的代碼:如何將焦點和閃光燈支持添加到相機

 protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; 
     width = Convert.ToInt32(Window.Current.Bounds.Width); 
     height = Convert.ToInt32(Window.Current.Bounds.Height); 
     capturePreview.Width = width; 
     capturePreview.Height = height; 
     Starter(); 
    } 
    async private void Starter() 
    { 
     captureManager = new MediaCapture(); 
     await captureManager.InitializeAsync(); 
     StartCapturePreview_Click(); 
    } 

    async private void StartCapturePreview_Click() 
    { 
     capturePreview.Source = captureManager; 
     await captureManager.StartPreviewAsync(); 
    } 

    async private void StopCapturePreview_Click(object sender, RoutedEventArgs e) 
    { 
     await captureManager.StopPreviewAsync(); 
    } 

    //private void focus_Click(object sender, RoutedEventArgs e) 
    //{ 
     //FocusManager.TryMoveFocus(FocusNavigationDirection.Next); 

    //} 

    async private void CapturePhoto_Click(object sender, RoutedEventArgs e) 
    { 
     ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); 

     // create storage file in local app storage 
     StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
      "Photo.jpg", 
      CreationCollisionOption.ReplaceExisting); 

     // take photo 
     await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file); 

     // Get photo as a BitmapImage 
     BitmapImage bmpImage = new BitmapImage(new Uri(file.Path)); 

     // imagePreivew is a <Image> object defined in XAML 
     imagePreview.Source = bmpImage; 
    } 

什麼是添加焦點和閃光燈的最佳方式?我嘗試過使用FocusManager,但沒有成功使用它。

回答

1

我不能幫你用閃光燈,但重點我用這個上WP8.1RT:

private async void focus_Click(object sender, RoutedEventArgs e) 
{ 
    try 
    { 
     await captureManager.VideoDeviceController.FocusControl.UnlockAsync(); 
     var focusSettings = new FocusSettings(); 
     focusSettings.AutoFocusRange = AutoFocusRange.Normal; 
     focusSettings.Mode = FocusMode.Auto; 
     focusSettings.WaitForFocus = true; 
     focusSettings.DisableDriverFallback = false; 
     captureManager.VideoDeviceController.FocusControl.Configure(focusSettings); 
     await captureManager.VideoDeviceController.FocusControl.FocusAsync(); 
    } 
    catch {} 
} 

您可能需要一個矩形添加到您的capturePreview所以你可以看到上你正在關注的對象。 我不知道確切的尺寸,但在我的手機(Lumia 520,帶有4「屏幕)橫向,看起來相機在capturePreview的中心使用的面積大約爲150×100像素

+0

看來相機拍攝p中的整個捕獲預覽,有沒有辦法爲我做的重點工作還通過在區域手動按下我想集中 – IsaacDj

+0

我?我不知道,我只發現它集中在屏幕中心的物體上,我通過拍攝我的手並檢查哪些指紋和手跡最清晰,只有中心的部分是這樣,然後添加了ar矩形來查看物體在不再聚焦之前距物體中心多遠的距離。我不認爲重點領域可以移動。 – mcb

+0

如何添加矩形以查看焦點區域? – IsaacDj

0

您可以通過執行補充閃光:_captureManager.VideoDeviceController.FlashControl.AssistantLightEnabled = false/true;