首页 > 解决方案 > 如何正确拍摄和保存图像?

问题描述

我制作了一个 Win-Forms 应用程序,想从网络摄像头读取图像并将其保存到磁盘并在图片框中显示。一切正常,但是当我多次调用“Capture_Image()”函数时(在 button14-click 上)我得到一个错误,如“对象已在使用中”

using System;
using System.IO;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServices;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;

private VideoCapture capture = null;
private Bitmap tempImg = null;

public Form1()
{
    InitializeComponent();
    capture = new VideoCapture();
}

public void Capture_Image()
{
    try
    {
        capture.Start();
        tempImg = capture.QueryFrame().Bitmap;
        pictureBox2.Image = tempImg;
        pictureBox2.Refresh();
        tempImg.Save("C:/FHT59N3/Bildanalyse_Projekt/image.jpg",
        System.Drawing.Imaging.ImageFormat.Jpeg);
        capture.Stop();
    }
    catch (NullReferenceException)
    {
        string message = "No Camera found";
        string title = "Please connect Camera";
        MessageBoxButtons buttons = MessageBoxButtons.OK;
        MessageBox.Show(message, title, buttons, MessageBoxIcon.Warning);
    }
}

private void button14_Click(object sender, EventArgs e)
{
    Capture_Image();
}

我在捕获方面做错了吗?为什么我会收到此错误

标签: c#

解决方案


推荐阅读