问题描述
我有一个提供图像的IP摄像机。然后通过处理这些图片,然后我要显示处理过的图片。
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;
...
}
30fps网络摄像头。但是,当我通过浏览器访问它们时,IPCam的图像需要一秒钟到达这里。所以,在同一时间,WPF显示什么,甚至没有处理的以前的图像。
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.
如何让WPF至少显示上一张图片?
How can I get WPF to at least show the previous image?
推荐答案
您可以使用或并在WPF的Image控件中显示BitmapSource
或者你可以(对于30fps(和1fps)BitmapSource方法应该做的)。
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.
这篇关于显示来自IP摄像机的已处理图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!