Question

I have an IP-camera that serves images. These images are then processed via EmguCV and then I want to display the processed images.

To show the images, I use this code:

Window1(){
     ...
     this.Dispatcher.Hooks.DispatcherInactive 
         += new EventHandler(Hooks_DispatcherInactive);
}

Hooks_DispatcherInactive(...)
{
    Next()
}

Next() the calls calls the image processing methods and (should) display the image:

MatchResult? result = survey.Step();
if (result.HasValue)
{
    Bitmap bit = result.Value.image.Bitmap;
    ImageSource src = ConvertBitmap(bit);
    show.Source = src;
    ...
}

This works fine when I hook up a normal 30fps webcam. But, the IPCam's images take over a second to get here, also when I access them via a browser. So, in the mean time, WPF shows nothing, not even the previous image that was processed.

How can I get WPF to at least show the previous image?

Was it helpful?

Solution

You can copy the image's buffer into a new BitmapSource image of the same format (PixelFormat, Height, Width, stride) using Create (from Array) or Create (from IntPtr) and display that BitmapSource in WPF's Image control, or you can use DirectX to do that faster (for 30fps (and 1fps) the BitmapSource approach should do).

Also, consider NOT using events in the view, instead use bindings and commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top