我正在使用以实时模式拍摄图像的相机。每个新图像都通过事件句柄调用。 当我尝试将位图图像转换为wpf-image时,会出现问题( line : image1.Source = wpfBitmap )(此转换已经过测试并适用于单个图像)。以下代码用于事件和图像转换:
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);
}
错误如下所示:
有谁知道我如何避免这种异常?在此先感谢您的帮助...