我确实有以下情况(WPF;c#):
1)我初始化一个相机,并启动一个事件处理程序,在后台自动显示实时图像
2)之后,如果例如用户单击按钮,我想再次关闭这个打开的事件处理程序。问题:我怎么才能做到呢?
我代码:private void InitCamera(int CamID)
{
...
Camera.EventFrame += onFrameEventFocusCam; // start event
...
}
private void onFrameEventFocusCam(object sender, EventArgs e)
{
...
Dispatcher.Invoke(new Action(() =>
{
// Convert bitmap to WPF-Image
var bmp = new Bitmap(bitmap);
var hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
image_fokus.Source = wpfBitmap;
image_fokus.Stretch = System.Windows.Media.Stretch.UniformToFill;
DeleteObject(hBitmap);
bitmap.Dispose();
}
...
}
你试过了吗:
Camera.EventFrame -= onFrameEventFocusCam;