2

我正在为大学学校制作 C# 软件,我需要帮助:

在此处输入图像描述

使用的 Youtube 教程:http ://www.youtube.com/watch?v=CaYQLq72ZN4

捕获视频图像时发生错误。现在将终止视频捕获。你调用的对象是空的。

第一次执行该软件,它运行良好,现在当我关闭并再次打开时出现此错误(似乎有一个进程正在运行)。我遵循了 youtube 的教程,我注意到由于类似的错误而有很多投诉。它可以工作,但只有当你按 3 次“开始”按钮时,我才知道错误。

代码:

FRM:

using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

namespace WinApp_FingerControl
{
    public partial class Frm_CadastroCliente : Form
    {

        public Frm_CadastroCliente()
        {
            InitializeComponent();
        }
        WebCam webcam;
        private void Frm_CadastroCliente_Load(object sender, EventArgs e)
        {
            webcam = new WebCam();
            webcam.InitializeWebCam(ref imgVideo);
        }

        private void btn_IniciarCamera_Click(object sender, EventArgs e)
        {
            webcam.Start();
        }

        private void btn_Salvar_Click(object sender, EventArgs e)
        {
            Helper.SaveImageCapture(imgCapture.Image);
        }

        private void btn_FormatoVideo_Click(object sender, EventArgs e)
        {
            webcam.ResolutionSetting();
        }

        private void btnCapturar_Click(object sender, EventArgs e)
        {
            imgCapture.Image = imgVideo.Image;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webcam.AdvanceSetting();
        }


    }
}

网络摄像头.cs:

{

    class WebCam
    {
        private WebCamCapture webcam;
        private System.Windows.Forms.PictureBox _FrameImage;
        private int FrameNumber = 30;
        public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
        {
            webcam = new WebCamCapture();
            webcam.FrameNumber = ((ulong)(0ul));
            webcam.TimeToCapture_milliseconds = FrameNumber;
            webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
            _FrameImage = ImageControl;
        }

        void webcam_ImageCaptured(object source, WebcamEventArgs e)
        {
            _FrameImage.Image = e.WebCamImage;
        }

        public void Start()
        {
                webcam.TimeToCapture_milliseconds = FrameNumber;
                webcam.Start(0);
        }

        public void ResolutionSetting()
        {
            webcam.Config();
        }

        public void AdvanceSetting()
        {
            webcam.Config2();
        }

    }
}

助手.cs

class Helper
{

    public static void SaveImageCapture(System.Drawing.Image image)
    {

        SaveFileDialog s = new SaveFileDialog();
        s.FileName = "Image";// Default file name
        s.DefaultExt = ".Jpg";// Default file extension
        s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension

        // Show save file dialog box
        // Process save file dialog box results
        if (s.ShowDialog()==DialogResult.OK)
        {
            // Save Image
            string filename = s.FileName;
            FileStream fstream = new FileStream(filename, FileMode.Create);
            image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
            fstream.Close();

        }

    }
}
4

1 回答 1

-6

终止使用网络摄像头的其他应用程序(如 Skype)的进程,您的代码将运行。:)

于 2014-07-17T10:14:07.823 回答