BitmapFrame.Create的异常(WPF框架中的bug)? [英] Exception on BitmapFrame.Create (bug in WPF framework?)

查看:572
本文介绍了BitmapFrame.Create的异常(WPF框架中的bug)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个C帧应用程序,以30fps的帧速率收到帧RGB。



帧的到达事件由以下代码进行管理:

  void client_ColorFrameReady(object sender,ColorFrameReadyEventArgs e)
{
mycounter ++;
Console.WriteLine(new frame received:+ mycounter);

if(writer!= null)
{
count ++;
if(count%2 == 0)
{

using(var frame = BitmapImage2Bitmap(e.ColorFrame.BitmapImage))
using(var thumb = ResizeBitmap (框架,320,240))
{
writer.WriteVideoFrame(thumb);
}

}
}
else
{
writer.Close();
}
}

如果条件我只管理两个框架之一



当我的代码调用 BitmapImage2Bitmap 我得到这个例外:





英语中的异常应该是:

 PresentationCore.dll中发生了System.NotSupportedException类型的第一次机会异常
附加信息:BitmapMetadata不适用于BitmapImage。

奇怪的是,我的应用程序工作很好,因为框架正确插入输出文件。



我已阅读这个,所以问题似乎是WPF框架中的一个错误。

解决方案>

这是设计。第一次机会异常通知并不意味着有问题。 Create()方法中的相关代码如下所示:

  try 
{
metadata = source元数据作为位图元数据;
}
catch(NotSupportedException)
{
}



<换句话说,例外是预期的,只是吞咽。当您在Debug + Exception对话框中勾选Thrown复选框时,这些例外情况会使调试器停止,这当然非常烦人。但它肯定不是一个bug,这是有意的这样写的。有时候,让异常被抛出并吞下来,而不是编写防止异常的代码便宜得多。特别是当避免异常变得不切实际的时候,由于位图的种类很多,所以使用位图的情况。其中一些不支持元数据。无论在框架代码中完成哪里,几乎总是使代码更快地实现。速度也是代码的一个重要方面。



功能,而不是错误。取消抛出复选框以避免看到这些异常。


I implemented a C# application that recevies frame RGB at framerate of 30fps.

The event of frame arrive is managed with this code:

void client_ColorFrameReady(object sender, ColorFrameReadyEventArgs e)
        {
            mycounter++;
            Console.WriteLine("new frame received: " + mycounter);

            if (writer != null)
            {
                count++;
                if (count % 2== 0)
                {

                    using (var frame = BitmapImage2Bitmap(e.ColorFrame.BitmapImage))
                    using (var thumb = ResizeBitmap(frame, 320, 240))
                    {
                        writer.WriteVideoFrame(thumb);
                    }

                }
            }
            else
            {
                writer.Close();
            }
        }

with the if condition I manage only one of two frames.

When my code call BitmapImage2Bitmap I obtain this exception:

The exception in english should be:

A first chance exception of type 'System.NotSupportedException' occurred in `PresentationCore.dll`
Additional information: BitmapMetadata is not available on BitmapImage.

The strange thing is that my application works "well" because the frames are correctly inserted in the output file.

I've read this, so the problem seems a bug in WPF framework.

解决方案

This is by design. A first-chance exception notification doesn't mean that there's a problem. The relevant code inside the Create() method looks like this:

try
{
    metadata = source.Metadata as BitmapMetadata;
}
catch (NotSupportedException)
{
}

In other words, the exception is expected and simply swallowed. Which is certainly very annoying since these exceptions do make the debugger stop when you have the Thrown checkbox checked in the Debug + Exception dialog. But it certainly is not a bug, this was intentionally written this way. Sometimes it is a lot cheaper to just let an exception be thrown and swallowing it instead of writing the code that prevents the exception. Especially when it gets unpractical to avoid the exception, the case with bitmaps since there are so many different kind of bitmap types. Some of which don't support metadata. Wherever this is done inside the framework code, it is almost always done to make the code faster. Speed is also an important aspect of code.

Feature, not a bug. Untick the Thrown checkbox to avoid seeing these exceptions.

这篇关于BitmapFrame.Create的异常(WPF框架中的bug)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆