0
我最近想尝试AForge.NET,因为我发现它很简单,所以我决定使用Video.FFMPEG命名空间来做一些简单的视频回放,所以我可以将每个帧直接放在一个pictureBox上。这一方面效果很好,但我想在不重要的情况下处理每个图像,因为无需明显的原因,大约需要1.5GB的内存。这就是我的问题开始的地方。出于某种原因,它有时会抛出此异常(通常在调整窗口大小时)。我不确定可能是由什么造成的。也许这真的是一个愚蠢的错误。我的猜测是,这可能是由计时器造成的,但我可以完成一个完全不同的错误,但看不到它。这是我不断收到异常:pictureBox图像配置异常
************** Exception Text **************
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
这是代码(我也知道公共变量都不好,我只是在测试过程中的):
public long i = 0;
public Bitmap img;
public VideoFileReader reader;
public System.Timers.Timer aTimer;
public void render(object source, ElapsedEventArgs e)
{
if (img != null) img.Dispose();
if (i < reader.FrameCount)
{
img = reader.ReadVideoFrame();
pictureBox1.Image = img;
}
i++;
}
private void button1_Click(object sender, EventArgs e)
{
reader = new VideoFileReader();
aTimer = new System.Timers.Timer();
reader.Open("d:\\result.avi");
aTimer.Elapsed += new ElapsedEventHandler(render);
aTimer.Interval = reader.FrameRate;
aTimer.Enabled = true;
}