尝试使用以下代码将PhotoCamera设置为VideoBrush的源时出现上述错误:
camera = new PhotoCamera();
var videoBrush = new VideoBrush();
videoBrush.SetSource(camera);
AR.Background = videoBrush;
我得到以下堆栈跟踪:
0x80131515
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.VideoBrush_SetExternalVideoSource(VideoBrush vb, IntPtr& videoSessionHandle)
at System.Windows.Media.VideoBrush.SetUpExternalVideoSession()
at Microsoft.Devices.CameraVideoBrushExtensions.SetSource(VideoBrush brush, Camera camera)
at MyClass.MyFunction()
at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler`1 handler, Object sender, OrientationChangedEventArgs args)
at Microsoft.Phone.Controls.PhoneApplicationPage.UIOrientationChange(ShellPageOrientation orientation)
无论是否连接了调试器,都会引发异常。
谢谢。
最佳答案
好吧,我现在已经解决了这个问题。我认为该解决方案可能会受到其他人的赞赏,所以这里是;
似乎无法将PhotoCamera作为源分配给以编程方式创建的VideoBrush,因此我编辑了xaml以包含一个
<Rectangle>
<Rectangle.Fill>
<VideoBrush x:Name="VB" />
</Rectangle.Fill>
</Rectangle>
随后是一个简单的代码
VB.SetSource(new PhotoCamera());
此外,此代码包含在OnOrientationChanged事件中,该事件似乎多次触发,因此包含在
if (!processing)
{
processing = true;
VB.SetSource(new PhotoCamera());
var bw = new BackgroundWorker();
bw.DoWork += (object, sender) => {
Thread.Sleep(250);
processing = false;
}
}
代码运行流畅。