How to Set Brightness and Exposure for a Webcam Using C# and MediaFoundation
It’s incredibly hard to find the easiest way to control a webcam using MediaFoundation. It’s not that tough to stream the video or snap a photo but changing contrast and brightness and exposure… phew.
So, I thought I’d embed some code to make it easy for folks. Once you have an IMFMediaSource object (essentially the video player) you can cast it to the two necessary control interfaces. These then have get/set/getrange methods to set or get the values.
The trick is knowing the syntax and having the GUIDS and the definitions of the properties. Most of the work is documented here and there. The best source of information is Aforge.NET. If you go down the rabbithole of StackOverflow you'll be there for a long time and get nowhere.
The IAMCameraControl interface lets you control exposure and webcam stuff, for some reason. The IAMVideoProcAmp interface lets you control everything else, such as brightness, contrast, and gain. Note that in the code set below there’s also a small sample chunk showing how to use the interfaces once you have an IMFMediaSource.
Here’s the code: