c# - 如何正确拍摄和保存图像?
问题描述
我制作了一个 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();
}
我在捕获方面做错了吗?为什么我会收到此错误
解决方案
推荐阅读
- mongodb - Mongodb聚合(月)查询将“缺失字段”设置为零
- ajax - 从弹出窗口使用 AJAX 调用时,Kendo 网格更新不起作用
- python - 有没有办法使用自定义分布在 Python 中进行 Anderson Darling 测试?
- php - WordPress:无法设置 slug,因为存在同名图像
- apollo-client - 将自定义字段添加到 apollo makeVar
- sql - 在 SQL 中运行 Sum
- html - Blade.php 文件中 html 的 VS Code linter(未封闭标签检测)
- apache-nifi - NiFi 处理器无法连接到 Zookeeper
- vba - VBA .Findnext 卡在循环上
- vue.js - Vuetify 延迟加载tiptap 编辑器