I capture images from my web camera to Image control in WPF with WebCam_Capture.dll
. For every captured frame i have event called webCam_imageCaptured
. It calls every time when i receive new image from web camera. In this event I call method LoadBitmap
to get hBitmap and receive BitmapSource to put this captured picture to the Image control.
Here is code of this method:
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr handle);
public BitmapSource bs;
public IntPtr ip;
public BitmapSource LoadBitmap(System.Drawing.Bitmap source)
{
ip = source.GetHbitmap();
bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
return bs;
}
这里是活动守则:
private void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
//_frameImage is Image WPF control.
_frameImage.Source = LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
}
我在此有漏!! RAM装满了1支大不列颠和有时更多新娘! <代码>DeleteObject(ip)并非每次使用。 当RAM为1个或更多英镑时,它释放或显示我的记忆错误。 如何解决这一问题?