我正在使用AForge
类库。
在这个库中,我使用VideoSourcePlayer
来拍摄摄像头的照片。
我的目的是创建一个函数,允许用户拍摄图像,将它们建立为公司徽标。您不仅可以从计算机选择图像,而且还可以通过相机从外部捕获图像,因为您可能只想将物理支持(纸张)的徽标传输到程序中。
正如前面在SO,(how to pause a video file played using videosourceplayer)中所评论的,VideoSourcePlayer
没有Pause
方法或任何允许冻结图像的函数。
是的,它确实有GetCurrentFrame()
方法,但它只从必须传递给PictureBox
的当前帧中获取Bitmap
。
但我希望当用户单击按钮时,VideoSourcePlayer
模拟的图像被冻结,当用户因为不喜欢照片而按下Delete
按钮时,图像停止被冻结并恢复其移动。
逻辑就像暂停或播放视频一样。
嗯,没有办法,所以我决定寻找另一种方法来获得它,然后……
如果拍摄了一张照片,请使用包含最后一帧并显示在VideoSourcePlayer
上的PictureBox
,但如果将其删除,则会删除该PictureBox
,并将该VideoSourcePlayer
与视频一起返回。
private readonly Bitmap EmptyBitmap;
private void CaptureBtn_Click(object sender, EventArgs e)
{
Bitmap bitmap = this.VideoSource.GetCurrentVideoFrame();
ShowTakedFrame(bitmap, false);
}
private void ShowTakedFrame(Bitmap Frame, bool remove)
{
var picture = new System.Windows.Forms.PictureBox();
picture.Size = this.VideoSource.Size;
picture.Location = this.VideoSource.Location;
if (!remove)
{
this.VideoSource.Stop();
picture.Image = Frame;
this.Controls.Remove(VideoSource);
this.Controls.Add(picture);
}
else
{
this.Controls.Remove(picture);
this.Controls.Add(VideoSource);
this.VideoSource.VideoSource = this.CaptureDevice;
this.VideoSource.Start();
}
}
private void DeleteBtn_Click(object sender, EventArgs e)
{
ShowTakedFrame(EmptyBitmap, true);
}
我的问题是,当拍摄照片时,图像是在你按下Capture
按钮的那一刻之后的几秒钟,当你使用Delete
按钮删除捕捉到的图像时,VideoSourcePlayer
的视频被冻结。
有人能帮我一下吗?
发布于 2018-05-05 15:44:58
问题是,当您删除PictureBox
并添加VideoSourcePlayer
时,它会创建一个新对象,即不具有前一个对象的配置属性的对象。我的建议是您以不同的形式创建捕获。
https://stackoverflow.com/questions/49962097
复制