Menu Close

Why are brightness, contrast and grayscale not applied to the OnFrameBitmap bitmap?

Skip to main content
You are here:
Print

Why are brightness, contrast and grayscale not applied to the OnFrameBitmap bitmap?

Symptom

The frame grabber is enabled and VideoProcessing_Brightness, VideoProcessing_Contrast or VideoProcessing_GrayScale are set, but the bitmap received in the OnFrameBitmap event is not adjusted. This shows up when the application displays this bitmap itself, e.g. in a WPF Image control, instead of the TVideoGrabber video window.

Cause

By default (OverlayAfterTransform = false), the image adjustments (brightness, contrast, hue, saturation, grayscale, inverted colors) are applied after the OnFrameBitmap event and the overlays: the event receives the frame before the adjustments, while the frame passed to the video window and to the recording is adjusted.

Solution

Enable OverlayAfterTransform before starting the preview: the adjustments are then applied first, and OnFrameBitmap receives the adjusted frame.

private void StartBtn_Click(object sender, RoutedEventArgs e)
{
    videoGrabber.FrameGrabber = TFrameGrabber.fg_PreviewStream;
    videoGrabber.OnFrameBitmap += VideoGrabber_OnFrameBitmap;
    videoGrabber.OverlayAfterTransform = true;
    videoGrabber.StartPreview();
}

private void BrightnessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    videoGrabber.VideoProcessing_Brightness = (int)brightnessSlider.Value;   // -128..128
}

Side effect: with OverlayAfterTransform = true, the text and image overlays are drawn after the adjustments and keep their colors (for example, they are no longer converted to grayscale).

See also Image adjustments and OverlayAfterTransform in the documentation of the TVideoGrabber SDK.

Table of Contents