这段代码在Windows Forms应用程序中可行(它显示预览),但在WPF应用程序中不行。
WMEncoder _encoder;
WMEncDataView _preview;
_encoder = new WMEncoder();
IWMEncSourceGroupCollection SrcGrpColl = _encoder.SourceGroupCollection;
IWMEncSourceGroup2 sourceGroup = (IWMEncSourceGroup2)SrcGrpColl.Add("SG_1");
IWMEncVideoSource2 videoDevice = (IWMEncVideoSource2)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
videoDevice.SetInput("Default_Video_Device", "Device", "");
IWMEncAudioSource audioDevice = (IWMEncAudioSource)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
audioDevice.SetInput("Default_Audio_Device", "Device", "");
IWMEncProfile2 profile = new WMEncProfile2();
profile.LoadFromFile("Recording.prx");
sourceGroup.set_Profile(profile);
_encoder.PrepareToEncode(true);
_preview = new WMEncDataView();
int lpreviewStream = videoDevice.PreviewCollection.Add(_preview);
_encoder.Start();
_preview.SetViewProperties(lpreviewStream, (int)windowsFormsHost1.Handle);
_preview.StartView(lpreviewStream);
我尝试使用WindowsFormsHost控件获取句柄以传递(如示例所示),但仍然没有成功。