Click here to Skip to main content
11,575,923 members (55,531 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi All,

Sorry a newbiw question here. Hope no one minds as its probably a simple question?.

I have searched Google and cant find the answer anywhere, but then again I maybe looking at the wrong things ....

I have the following code in my Application:
void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
    picWebCam.Image = bit;
}
I need to call 'bit.dispose();' from 'void cam_NewFrame' but from within:
private void btnStop_Click(object sender, EventArgs e)
{
    cam.Stop();
    bit.dispose(); // Need to add in here
}
Obviously this isnt working as its in a different class(?)?

How can i call bit.dispose from my btnStop?

Many Thanks
SJG
Posted 16-Feb-13 9:14am
Comments
Sergey Alexandrovich Kryukov at 16-Feb-13 19:20pm
   
Simple questions are just fine, but they should be formulated correctly.
Is it AForge.NET? You cannot show the code without any references to types (libraries) you use.
You should always show where you add an event handler to the invocation list of the event (NewFrame?). Who knows what cam_NewFrame really is? You should always rename all auto-generated names...
Your "it's not working" is not informative at all.
—SA
sjg2004_01 at 17-Feb-13 6:26am
   
Hi All,

OrgiginalGriff,

Many thanks for you reply. I cannot modify the cam.Class as its a pre-compiled DLL which is iported into my project..

Sergey Alexandrovich Kryukow,

You are correct. This is for AForge.Net . Both classes are on my main form. Hopefully pasteing all my code should help?

All the code for my main form is:

Collapse | Copy Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Xml;

namespace TestApplication
{
public partial class frmMain : Form
{
// Needed for Video Capture (AForge Video)
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;

private void frmMain_Load(object sender, EventArgs e)
{
#region Video Capture Functions
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
cboSelectCamera.Items.Add(VideoCaptureDevice.Name);
}

cboSelectCamera.SelectedIndex = 0;

cam = new VideoCaptureDevice(webcam[cboSelectCamera.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
#endregion
}

private void btnSnap_Click(object sender, EventArgs e)
{
picDBImage.Image = picWebCam.Image;
}

private void btnStartStreaming_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(webcam[cboSelectCamera.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}

private void btnStopStreaming_Click(object sender, EventArgs e)
{
if (cam.IsRunning)
{
cam.Stop();
}
}

private void btnStart_Click(object sender, EventArgs e)
{
cam.Start();
}

private void btnStop_Click(object sender, EventArgs e)
{
cam.SignalToStop();
cam.Stop();

// Need to add in and call cam_NewFrame - bit.dispose here
}

#region Video Functions
private void btnTakePhoto_Click(object sender, EventArgs e)
{
sfdCameraImage.InitialDirectory = @"C:\";
if (sfdCameraImage.ShowDialog() == DialogResult.OK)
{
cam.Stop();
picDBImage.Image.Save(sfdCameraImage.FileName);
}
}

void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
picWebCam.Image = bit;
}
#endregion
}
}

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Why not dispose it in the cam class? It's part of the class, so disposing of it in the Stop method would make sense to me!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 305
1 F-ES Sitecore 145
2 OriginalGriff 125
3 Abhinav S 98
4 Dave Kreskowiak 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100