Reputation: 271
I do have following situation (WPF; C#):
1) I initialize a camera and starting an event-handler which displays the live-image automatically in the background
2) Afterwards I would like to close this open event-handler again if for example the user clicks a button. Question: How can I do that?
My code:
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();
}
...
}
Upvotes: 1
Views: 454