locked
Change Camera settings in Code RRS feed

  • Question

  • Hello All,

    I am looking for a way to change camera settings(such brightness,etc) via javascript code. Because I dont want to use the default camera setting UI. I can  successfully get the ViewDeviceController from a MediaCapture instance . But it seems all the setting properties are read only. Can anyone point me to the right direction?

    Thanks anyway~

    Wednesday, July 18, 2012 6:19 AM

Answers

  • Hi

    You can change the camera settings by mediaCapture.videoDeviceController.

    Here is the code sample:

     function getCameraSettings() {
            var mediaCaptureMgr = null;
            //Set up brightness and contrast controls
            var controller = mediaCaptureMgr.videoDeviceController;
            
            
            cameraControlSliders = new Array(
            {
                control: controller.brightness, slider: id("rngBrightness")
    /*a slider in Page<td>Brightness</td><td><input type="range" id="rngBrightness" style="width: 200px"></td>*/
            },
            {
                control: controller.contrast, slider: id("rngContrast")
            });
            for (var i = 0; i < cameraControlSliders.length; i++) {
                cameraControlSliders[i].handler = (function (_control, _slider) {
                    return function () {
                        _control.trySetValue(parseInt(_slider.value));
                    };
                })(cameraControlSliders[i].control, cameraControlSliders[i].slider);
            }
            controller = null;
            window.CollectGarbage();
        }

    You can get this sample code from msdn:

    Media capture using capture device sample

    • Marked as answer by ILOVEWCF Friday, July 20, 2012 10:45 AM
    Friday, July 20, 2012 8:09 AM

All replies

  • Hi

    This sample demonstrates how to create a Metro style device app for a camera. A Metro style device app is provided by an IHV or OEM to differentiate the capture experience for a particular camera. It can be used to adjust camera settings or to provide additional functionality or effects.
    Thursday, July 19, 2012 12:54 PM
  • Hi

    You can change the camera settings by mediaCapture.videoDeviceController.

    Here is the code sample:

     function getCameraSettings() {
            var mediaCaptureMgr = null;
            //Set up brightness and contrast controls
            var controller = mediaCaptureMgr.videoDeviceController;
            
            
            cameraControlSliders = new Array(
            {
                control: controller.brightness, slider: id("rngBrightness")
    /*a slider in Page<td>Brightness</td><td><input type="range" id="rngBrightness" style="width: 200px"></td>*/
            },
            {
                control: controller.contrast, slider: id("rngContrast")
            });
            for (var i = 0; i < cameraControlSliders.length; i++) {
                cameraControlSliders[i].handler = (function (_control, _slider) {
                    return function () {
                        _control.trySetValue(parseInt(_slider.value));
                    };
                })(cameraControlSliders[i].control, cameraControlSliders[i].slider);
            }
            controller = null;
            window.CollectGarbage();
        }

    You can get this sample code from msdn:

    Media capture using capture device sample

    • Marked as answer by ILOVEWCF Friday, July 20, 2012 10:45 AM
    Friday, July 20, 2012 8:09 AM
  • Hi Dino,

    Thanks for the relply. Your answer is mostly correct. You should initialize mediaCapture instance before use it and for others who are trying to implement this:

    1. You can get the videoDeviceController after the MediaCapture is initialized.

    2. You shall read the settings after the camera started or you will get nothing.(Maybe because my camera is too cheap?)

    Best Regards.

    Friday, July 20, 2012 10:45 AM