payam1363
payam1363

Reputation: 11

About Bitmap frame = new Bitmap(files[index])

I have written some software that records from Gig-E cameras software record raw by streamwriter and my software can show the recorded video by streamreader.

Now, in this part of my software, I want to change recorded video to .mp4 to show in a normal video player, but my Visual Studio gives this error:

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

Additional information: Parameter is not valid.

Code:

private void DownloadVideo()
{
int selectedRow = utility.GetSelectedRow(this.dataGridView1);
if (selectedRow == -1)
return;
string path = Directory.GetCurrentDirectory() + "\saved\" + ((string) this.dataGridView1.Rows[selectedRow].Cells[1].Value).ToString();
string currentDirectory = Directory.GetCurrentDirectory();
if (this.saveFileDialog1.ShowDialog() == DialogResult.Cancel)
{
Directory.SetCurrentDirectory(currentDirectory);
}
else
{
Directory.SetCurrentDirectory(currentDirectory);
string fileName = this.saveFileDialog1.FileName;
string[] files = Directory.GetFiles(path);
int width = 800;
int height = 600;
VideoFileWriter videoFileWriter = new VideoFileWriter();
videoFileWriter.Open(fileName, width, height, 25, VideoCodec.MPEG4);
TimeSpan timestamp = new TimeSpan(0, 0, 0, 10);
for (int index = 0; index < files.Length; ++index)
{
Bitmap frame = new Bitmap(files[index]);
videoFileWriter.WriteVideoFrame(frame, timestamp);
}
videoFileWriter.Close();
int num = (int) MessageBox.Show("successfully saved");
}
}

Upvotes: 1

Views: 77

Answers (0)

Related Questions