secile / UsbCamera

C# source code for using usb camera and web camera in WinForms/WPF. With only single CSharp source code. No external library required.
MIT License
179 stars 55 forks source link

Setting gain and exposure time #10

Closed ali-imanpour closed 2 years ago

ali-imanpour commented 2 years ago

How can I set gain and exposure time?

secile commented 2 years ago

Hello.

This is a sample code modifying exposure and gain. It is no guarantee to support those properties in your camera, you had better check prop.Available property before use.

    UsbCamera.PropertyItems.Property prop;
    prop = camera.Properties[DirectShow.CameraControlProperty.Exposure];
    if (prop.Available)
    {
        prop.SetValue(DirectShow.CameraControlFlags.Manual, prop.Default);
    }

    prop = camera.Properties[DirectShow.VideoProcAmpProperty.Gain];
    if (prop.Available && prop.CanAuto)
    {
        prop.SetValue(DirectShow.CameraControlFlags.Auto, 0);
    }