我正在尝试找出如何从过滤器中获取位图数据。我正在使用DirectShowNet包装器从网络摄像头获取图像。
我当前的代码是:
public partial class Form1 : Form
{
public IGraphBuilder gb;
public ICaptureGraphBuilder2 cgb;
public IBaseFilter filter;
public Form1()
{
InitializeComponent();
DsDevice[] videoInputDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
object obj = null; Guid iid = typeof(IBaseFilter).GUID;
videoInputDevices[1].Mon.BindToObject(null, null, ref iid, out obj);
filter = (IBaseFilter)obj;
((IAMCameraControl)filter).Set(CameraControlProperty.Exposure, 0, CameraControlFlags.Auto);
gb = (IGraphBuilder) new FilterGraph();
cgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
cgb.SetFiltergraph(gb);
gb.AddFilter(filter, "First Filter");
cgb.RenderStream(PinCategory.Preview, MediaType.Video, filter, null, null);
((IVideoWindow)gb).put_Owner(this.panel1.Handle);
((IVideoWindow)gb).put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
((IVideoWindow)gb).put_Visible(OABool.True);
((IVideoWindow)gb).SetWindowPosition(0, 0, this.panel1.Width, this.panel1.Height);
((IMediaControl)gb).Run();
}
}
这个简单的代码只是将webcamera的输出呈现给面板控件。我尝试使用计时器和SaveToBitmap函数将图像从面板复制到位图,但此后位图为空白。
我读了一些有关Grabber过滤器的内容,但是我的解决方案没有用,它向缓冲区/样本返回了null ptr。
我想问一下,我应该添加什么才能读取图像数据?非常感谢你。
DirectShow管道的标准行为是,过滤器将数据彼此传递而不将数据显示给控制应用程序和代码,因此没有直接访问数据的方法。
您通常执行以下操作之一:
两种方法都有记录,流行和讨论过多次,包括在StackOverflow上:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句