none
[W8.1][XAML][C#] VideoDeviceController.Zoom actual upper limit for values is lower than Maximum property value.

    Question

  • My Windows Store app currently targets Windows 8.1. I am in the process of implementing my own camera capture dialog using Windows.Media.Capture.MediaCapture to replace the one provided by Windows.Media.Capture.CameraCaptureUI as I do not wish to display a second window while capturing in Windows 10. The latest (and only remaining?) version of official docs for MediaCapture recommends using VideoDeviceController.ZoomControl to change the device zoom. As this newer member is not available on the 8.1 version of VideoDeviceController, I am using the Zoom member instead.

    Once the MediaCapture instance has been initialized and the user's preferred media stream encoding profile has been set, I use Zoom.Capabilities to gather information about the minimum and maximum zoom values handled by the device. Elsewhere I use Zoom's TrySetValue method to set a valid value for the camera zoom.


    private void UpdateCameraZoom() { var deviceZoom = _mediaCapture.VideoDeviceController.Zoom; // Used to show/hide a slider control for Zoom IsZoomSupported = deviceZoom.Capabilities.Supported; if (IsZoomSupported) { ZoomMax = deviceZoom.Capabilities.Max; ZoomMin = deviceZoom.Capabilities.Min; ZoomStep = deviceZoom.Capabilities.Step; Zoom = deviceZoom.Capabilities.Min; } }

    // ...

        public double Zoom
        {
            get { return _zoom; }
            set
            {
                double approximateValue;
                if (value < ZoomMin)
                {
                    approximateValue = ZoomMin;
                }
                else if (value > ZoomMax)
                {
                    approximateValue = ZoomMax;
                }
                else
                {
                    approximateValue = value - (value % ZoomStep);
                }

                if (_mediaCapture.VideoDeviceController.Zoom.TrySetValue(approximateValue))
                {
                    _zoom = approximateValue;
                }
            }
        }

    For any given device set to one of its lower-resolution encodings, the device respond to changes in zoom value from the min value all the way up to the max value as expected. However, at higher resolutions there is some point on the scale of Zoom values between the reported min and max where any further increase does not result in a change in zoom. (Even though TrySetValue returns true for all values along the scale.) A Slider control for zoom is shown to the user based on the true value of Zoom.Capabilities.Supported, but re-setting the zoom value does not result in an actual zoom, especially at at higher resolutions like 1080p. I would hate to have to disable the zoom feature for all users just because some devices report incorrect max values when used with higher resolutions.

    I tried comparing resolution values with the point on the scale of values for Zoom where the camera stops zooming. I can see that there is a similar inverse relationship for devices, but the exact relationship is not constant between devices.

    Is there some some device-independent mathematical formula for re-interpreting Zoom's Min/Max values according to media stream encoding resolution? Have I made some other error in my implementation?

    UPDATE: The code I originally provided was intended to show where I get the values for ZoomMin, ZoomMax, and ZoomStep properties, and how they are used to ensure only valid values are sent to Zoom.TrySetValue(). The original code included poor thinking so I have replaced it with hopefully more logical code that will not distract from the main question.

    • Edited by Christian Albert Thursday, November 15, 2018 12:51 AM illogical code in snippet
    Thursday, November 8, 2018 6:11 AM

All replies

  • Hi,

    I have created two project , one is for windows 8.1 and another is for windows 10, the two apps use VideoDeviceController.Zoom to zoom in and out. The camera is Microsoft Lifecam 3000 USB Camera, the resolution is 720p. If zoom the capture with TrySetDeviceZoom in your post,  the picture can not zoom actual. I have a question is that why you used zoom - (zoom % ZoomStep). MediaDeviceControlCapabilities.Step Property is the smallest increment for zooming in/out. In your formula, if the zoom value is 5 and ZoomStep is 1, this mathematical formula result will be always 5, so even the result of TrySetValue is true, actually the media could not change the zoom. I have no 1080P device to test this issue, I tried to change the code as following, it works fine in windows 8.1 app and windows 10 app. The zoom max/min value is the camera setting, but not according to media stream encoding resolution.

    Here is my code for test.

            private bool TrySetDeviceZoom(ZoomType zoomType)
            {
                if (zoomType == ZoomType.In)
                {
                    Zoom += ZoomStep;
                }
                else
                {
                    Zoom -= ZoomStep;
                }
    
                if (Zoom < ZoomMin)
                {
                    Zoom = ZoomMin;
                }
                else if (Zoom > ZoomMax)
                {
                    Zoom = ZoomMax;
                }
    
                return _mediaCapture.VideoDeviceController.Zoom.TrySetValue(Zoom);
            }
    

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 9, 2018 10:01 AM
    Moderator
  • Hi Roy,

    Thank you for your feedback. In my original question I included code to show that I was indeed passing only valid values to VideoDeviceController.Zoom.TrySetValue(). (Here I take "valid" to mean "exact multiples of the Step value between the Minimum and Maximum values") The value I send to the setter comes from a Slider control whose StepFrequency is bound the the ZoomStep property, so in theory value - (value % ZoomStep) is unneeded. I leave it in the code above to highlight that I am indeed sending exact multiples of the Step increment to TrySetValue. As you kindly pointed out, the code I presented was confusing, so I have updated the question with different code that will hopefully not distract from the main topic. I made the same changes to my actual code, but still observed the same problematic behavior.

    Thank you also for your research. Were you able to confirm in your test projects that the zoom incremented all the way up to the stated Maximum value? This is my main problem.

    To give a concrete example:

    On a Surface Pro 2 and using the back-facing camera, Zoom.Capabilities reports the following values:
    Minimum: 0, Maximum: 317, Step: 1

    Using the smallest stream encoding of 160 x 120, Zoom.TrySetValue() returns true for all values up to and including 317.
    My UI has buttons to increment and decrement the zoom value (similar to what you showed with your code). Starting at the minimum zoom value and incrementally increasing the zoom value, the preview image zoom only seems to increase up to a value of 270 (based on naked-eye observations, so admittedly not very scientific.)
    For values beyone 270, TrySetValue still returns true, but there is no observable change.

    At 320 x 240, the observable change stops at 170.
    At 640 x 480, it stops at 70.

    I have observed the same phenomenon with a Logicool C920 webcam, HP115 tablet, and Surface Pro 4 as well.

    Does the device's Zoom.Maximum value require conversion based on image resolution?

    Thursday, November 15, 2018 1:09 AM
  • Hi,

    I'm sorry to say that I do not have a Surface Pro 4 or Surface Pro 2 here for testing. Currently I have two suggestions for this issue. The first is that you could try to upgrade your app from W8 to UWP. Try to use VideoDeviceController.ZoomControl Property instead of using VideoDeviceController.Zoom. See if this issue is still there.

    Another way is that you could try to open a support ticket for this. Please contact our paid phone support at MS Support. You will get 1:1 support on that. Please kindly note that your support ticket will be free if it is Microsoft's issue.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 15, 2018 10:00 AM
    Moderator