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;
}