FocusEtPoint在CaptureElement Windows应用商店中

时间:2015-10-22 11:21:21

标签: c# .net image windows-store-apps windows-8.1

我正在使用Windows应用商店应用程序以特定的格式和大小制作照片并存储。是否可以点击屏幕上的照片,焦点和白平衡在此点设置。 为此,我使用CaptureElement但不能设置焦点坐标。

在Windows Phone Link中,这是可能的请参阅:PhotoCamera.FocusAtPoint。在" Windows应用商店.NET" Windows 8.1 Library我找不到这个选项。

有人可以提供帮助。

最好的问候

1 个答案:

答案 0 :(得分:0)

您可以使用感兴趣的区域进行聚焦。

https://msdn.microsoft.com/en-us/library/windows.media.devices.regionsofinterestcontrol.aspx

以下是实施细节:

要获得用户的点击事件以获得触摸焦点,您可以获得覆盖整个取景器的网格,使不透明度非常低,以使其不可见:

<Grid x:Name="tapROIGrid" Tapped="tapROIGrid_Tapped" Background="White" Opacity="0.001"/>

在点击事件中,请注意我在点击位置周围的50 * 50 UI像素作为感兴趣的区域:

private async void tapROIGrid_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
    if (media capture not initialized || focus not supported || roi auto focus not supported)
        return;


    VideoEncodingProperties properties = MediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
    uint CurrentViewFinderResWidth = properties.Width;
    uint CurrentViewFinderResHeight = properties.Height;

    _vfResToScreenFactor = ((double)CurrentViewFinderResHeight) / _tapROIGrid.ActualHeight;
    var pos = e.GetPosition(sender as UIElement);
    var point1 = new Point( (pos.X - 25) * _vfResToScreenFactor, (pos.Y - 25) * _vfResToScreenFactor);
    if (point1.X < 0)
        point1.X = 0;
    if (point1.Y < 0)
        point1.Y = 0;

    var point2 = new Point((pos.X + 25) * _vfResToScreenFactor, (pos.Y + 25) * _vfResToScreenFactor);
    if (point2.X > ((double)CurrentViewFinderResWidth))
        point2.X = ((double)CurrentViewFinderResWidth);
    if (point2.Y > ((double)CurrentViewFinderResHeight))
        point2.Y = ((double)CurrentViewFinderResHeight);

    var region = new RegionOfInterest();
    region.Bounds = new Rect(point1, point2);
    region.BoundsNormalized = false;
    region.AutoFocusEnabled = true;
    region.AutoExposureEnabled = true; //this will make exposure for roi
    region.AutoWhiteBalanceEnabled = true; //this will make wb for roi
    var List<RegionOfInterest> RoiRegions new List<RegionOfInterest>(1);
    RoiRegions.Add(region);

    await _app.VM.MediaCapture.VideoDeviceController.RegionsOfInterestControl.ClearRegionsAsync();
    await _app.VM.MediaCapture.VideoDeviceController.RegionsOfInterestControl.SetRegionsAsync(RoiRegions, true);

    //note: before focusing, make sure or set single focus mode. That part of code not here.
    await FocusAsync();
}