I am using a camera which captures images in a live mode. Every new image is called via an event handle. The problem occurs (line: image1.Source = wpfBitmap) when I try to convert the bitmap image to a wpf-image (this conversion is tested and works for a single image). Following code is used for the event and image conversion:
private void onFrameEvent(object sender, EventArgs e)
{
uEye.Camera Camera = sender as uEye.Camera;
Int32 s32MemID;
Camera.Memory.GetActive(out s32MemID);
// Read Camera bitmap
Bitmap bitmap;
Camera.Memory.ToBitmap(s32MemID, out bitmap);
// 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());
image1.Source = wpfBitmap;
image1.Stretch = System.Windows.Media.Stretch.UniformToFill;
DeleteObject(hBitmap);
}
The error looks like this:
Does anyone know how I avoid this exception? Thanks in advance for the help...