Kruljac Marijan
Kruljac Marijan

Reputation: 3

FocusAtPoint in CaptureElement Windows Store App

I'm working on a Windows Store App makes that photos in a specific format and size, and stores. Is it possible to tap the photo on the screen what the focus and white balance set on this point. For this I use the CaptureElement but can not set the focus coordinates.

In a Windows Phone Link this is possible See: PhotoCamera.FocusAtPoint. In the "Windows Store Apps .NET" Windows 8.1 Library I do not find this option.

Can somebody help.

Best Regards

Upvotes: 0

Views: 190

Answers (1)

Waqas
Waqas

Reputation: 92

You can use regions of interest for tap to focus.

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

and here are implementation details:

To get tapped event from user for touch focus you can have e.g. a grid covering whole view finder, make opacity very low so that it's not visible:

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

in tapped event, notice that I am making a 50*50 UI pixel around tapped location as region of interest:

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

Upvotes: 0

Related Questions