ウェブカメラのキャプチャ画像を自動的に保存しようとすると、ランタイム エラーが path.automaticaly の名前 (0.jpg、02.jpg、03.jpg など) で発生します。このように、画像は特定の言及フォルダーに保存されます。エラー。これをチェックしてください。
namespace camera1
{
public partial class Form1 : Form
{
private Capture capture;
private bool captureinprogress;
public Form1()
{
InitializeComponent();
}
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
cameraimage.Image = ImageFrame;
string root = "C:\\photo\0"; // automatically saving image to c drive like 001.jpg,002.jpg;
for (int i = 0; i < 100; i++)
{
if (File.Exists(" "))
{ }
else
{
string Path = root + i + ".jpg";
ImageFrame.Save(Path);
}
{
if (ImageFrame != null)
{
pictureBox1.Image = ImageFrame.ToBitmap();
}
if (pictureBox1 != null)
{
pictureBox2.Image = ImageFrame.ToBitmap();
}
if (pictureBox2 != null)
{
pictureBox3.Image = ImageFrame.ToBitmap();
}
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (capture == null)
{
try
{
capture = new Capture();
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
if (capture != null)
{
if (captureinprogress)
{ //if camera is getting frames then stop the capture and set button Text
// "Start" for resuming capture
btnstart.Text = "Start!"; //
Application.Idle -= ProcessFrame;
}
else
{
//if camera is NOT getting frames then start the capture and set button
// Text to "Stop" for pausing capture
btnstart.Text = "Stop";
Application.Idle += ProcessFrame;
}
captureinprogress = !captureinprogress;
}
}
private void ReleaseData()
{
if (capture != null)
capture.Dispose();
}
}
}