c# - AForge.Video / Materialskin 反复导致stackoverflow
问题描述
好的,我正在使用 Materialskin 和 AForge 制作一个很好的应用程序,它可以有相机预览,在图片框中显示它们,然后可以保存。
这是我认为导致错误的代码部分
VideoCaptureDevice videoSource;
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
int imgCropHeight = 300;
int imgCropWidth = 500;
int imgCropX = 400;
int imgCropY = 300;
bool isCameraRunning = true;
public async void AForgeLoadDevice()
{
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
cameraList.Items.Add(VideoCaptureDevice.Name);
}
cameraList.SelectedIndex = 0;
await Task.Delay(90);
}
public void AForgeOpen()
{
try
{
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[cameraList.SelectedIndex].MonikerString);
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
} catch(Exception err)
{
MessageBox.Show(err.ToString());
}
}
public void AForgeClose()
{
FinalVideo.Stop();
}
async void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
Crop crop = new Crop(new Rectangle(imgCropX, imgCropY, imgCropWidth, imgCropHeight));
Bitmap newImage = crop.Apply(video);
pictureBox1.Image = newImage;
await Task.Delay(50);
}
我曾尝试在创建新表单时使用块,但这并没有解决任何问题。我从未在 Visual Studio 中收到过 stackoverflow 错误,所以我不太了解它,但我只知道它说它必须是由于 AForge / MaterialSkin 之类的框架而发生的
有什么修复吗?这真的很有帮助。
我认为它与 NewFrameEvent 处理程序有关,因为它确实是导致堆栈溢出的唯一方法
编辑:这通常发生在保持表单打开很长时间(1 分钟以上)或关闭并重新创建(我有一个 onclose 事件会停止伪造视频源)之后
解决方案
推荐阅读
- python - 我有月度数据,有没有一种快速分割索引和绘图的方法?
- java - 发布spring事件时如何在UML中表示一个类调用另一个类方法
- python - Google PlayStore Api - python 库访问
- opengl - opengl glTexSubImage 用于纹理数组
- node.js - 以角度形式将经纬度添加到数据库
- sql - 复杂的 Postgres 查询问题
- ios - UE4 - 无法将 Unreal Live 链接与 iPhone X Live Link Face 应用程序连接?
- django - 如何在 Django 中只接受超过 18 年前的日期输入
- mongodb - 访问 mongoDb $match 聚合管道中的变量字段
- javascript - 如何使用 sinon 进行单元测试?