title: WPF bitmap to image conversion shows a black image only
body: <p>I do have some problems to display an image (uEye-Cam) in a wpf-Image form. The displayed
  image is completely black. Below is my used code:</p>
  
  <pre><code>//Get Cam Bitmap Image
  var cam = new uEye.Camera();
  cam.Init();
  cam.Memory.Allocate();
  cam.Acquisition.Capture(uEye.Defines.DeviceParameter.DontWait);
  
  Int32 s32MemId;
  cam.Memory.GetActive(out s32MemId);
  cam.Memory.Lock(s32MemId);
  
  Bitmap bitmap;
  cam.Memory.ToBitmap(s32MemId, out bitmap);
  
  //WPF Image control
  System.Windows.Controls.Image img = new System.Windows.Controls.Image();
  
  //convert System.Drawing.Image to WPF image
  System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bitmap);
  IntPtr 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;
  image1.Visibility = Visibility.Visible;
  </code></pre>
  
  <p>Does anybody know why I see only a black image (The cam is working!)?
  Thanks in advance for the help</p>
  
  <hr>
  
  <p>Edit (as a reaction to answers/comments):</p>
  
  <p>I am using WPF not WinForms in my application.</p>
  
  <p>You are right the "img" was not used and therefore not correct. I changed the code accordingly and implemented the DeleteObject. My code looks like this now:</p>
  
  <pre><code>//WPF Image control
  var image1 = new System.Windows.Controls.Image();
  
  //convert System.Drawing.Image to WPF image
  var bmp = new System.Drawing.Bitmap(bitmap);
  IntPtr 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;
  image1.Visibility = Visibility.Visible;
  
  DeleteObject(hBitmap);
  </code></pre>
  
  <p>The difference to before is that I see a WHITE image instead of a black image. I am not sure why it does not gives me back the cam-image. Is there anything wrong with the image1 properties maybe or..?</p>
  
  <p>Thanks</p>