如何为相机添加对焦和闪光灯支持

How to add focus and flash support to camera

我正在为 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 但没有成功。

闪光灯我帮不了你,但为了对焦,我在 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 中添加一个矩形,以便您可以看到您正在关注哪个对象。 我不知道确切的尺寸,但在横向方向的 phone(Lumia 520 和 4" 屏幕)上,相机似乎在 [= 的中心使用了大约 150 x 100 像素的区域15=]捕捉预览.

您可以通过以下方式添加闪光灯:_captureManager.VideoDeviceController.FlashControl.AssistantLightEnabled = false/true;