Memory reached to one extreme and application stopped working. I called the Runcamera in a timer. for the resolution 640*480 but having problem with 1920*1080. What am I missing?
public void RunCamera()
{
imgWeb.Visibility = Visibility.Visible;
capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920);
capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080);
currentFrame = capture1.QueryFrame();
imgWeb.Source = ToBitmapSource(currentFrame);
}
ToBitmapSource defenition given below
public static BitmapSource ToBitmapSource(IImage image)
{
BitmapSource bs = null;
using (System.Drawing.Bitmap source = image.Bitmap)
{
try
{
IntPtr ptr = source.GetHbitmap(); //obtain the Hbitmap
bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ptr,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ptr); //release the HBitmap
}
catch (Exception ex)
{
GC.Collect();
GC.WaitForFullGCComplete();
}
return bs;
}
}