System.ArgumentException: "Недопустимый параметр." в bitmap
есть код на запись екрана в файл. После нажатия button1 программа работает 20 секунд, и выключается с ошибкой System.ArgumentException: "Недопустимый параметр." на этой bp = new Bitmap(1920, 1080); или на этой gr.CopyFromScreen(0, 0, 0, 0, bp.Size); строчке, в чем может быть проблема?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Accord.Video.FFMPEG;
namespace Screen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap bp;
Graphics gr;
VideoFileWriter vf;
string path = @"C:\Users\gmoss\OneDrive\Рабочий стол\video.avi";
private void button1_Click(object sender, EventArgs e)
{
vf = new VideoFileWriter();
vf.Open(path, 1920, 1080, 24, VideoCodec.MPEG4, 100000000);
timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
vf.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1 = new Timer();
timer1.Interval = 24;
timer1.Tick += timer1_Tick;
}
private void timer1_Tick(object sender, EventArgs e)
{
bp = new Bitmap(1920, 1080);
gr = Graphics.FromImage(bp);
gr.CopyFromScreen(0, 0, 0, 0, bp.Size);
pictureBox1.Image = bp;
vf.WriteVideoFrame(bp);
}
}
}