FocusAtPoint在CaptureElement Windows Store应用程序

本文关键字:Store 应用程序 Windows CaptureElement FocusAtPoint | 更新日期: 2023-09-27 18:18:45

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

在Windows Phone链接中这是可能的,参见:PhotoCamera.FocusAtPoint。在"Windows Store Apps . net"Windows 8.1库中,我没有找到此选项。

谁来帮帮忙。

FocusAtPoint在CaptureElement Windows Store应用程序

您可以使用感兴趣的区域点击来聚焦。

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();
}