Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 避免PresentationCore.dll中的System.Runtime.InteropServices.COMException_C#_Wpf - Fatal编程技术网

C# 避免PresentationCore.dll中的System.Runtime.InteropServices.COMException

C# 避免PresentationCore.dll中的System.Runtime.InteropServices.COMException,c#,wpf,C#,Wpf,我知道已经有其他问题了,但我无法从中找到问题的答案 我是WPF的新手,我正在构建媒体播放器,其中还包括显示图像。其中一个选项是平铺图像。就是这样做的: private void TilePic(string path) { var containerWidth = MyMainWindow.Width; double xPos = 0; double yPos = 0; Image image = null; var imageSource = new B

我知道已经有其他问题了,但我无法从中找到问题的答案

我是WPF的新手,我正在构建媒体播放器,其中还包括显示图像。其中一个选项是平铺图像。就是这样做的:

private void TilePic(string path) {
    var containerWidth = MyMainWindow.Width;
    double xPos = 0;
    double yPos = 0;
    Image image = null;
    var imageSource = new BitmapImage(new Uri(path.Replace("/", "\\")));
    while (yPos < MyMainWindow.Height) {
        while (xPos < MyMainWindow.Width) {
            image = new Image();
            ImageBehavior.SetAnimatedSource(image, imageSource);
            image.Margin = new Thickness(xPos, yPos, 0, 0);
            image.Width = imageSource.Width;
            image.Height = imageSource.Height;
            MainGrid.Children.Add(image);
            xPos += imageSource.Width;
        }
        xPos = 0;
        yPos += imageSource.Height;
    }
}
图像很小,但很长,对于1920x1080屏幕,这会增加约50幅图像

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
at System.Windows.Media.Imaging.RenderTargetBitmap.CopyCommon(RenderTargetBitmap sourceBitmap)
我知道这是关于太多的GDI句柄。使用GDIView,我可以看到它有大约7000个区域句柄。有人能告诉我这里发生了什么以及如何避免这种情况吗

编辑:好的,以下是异常详细信息,如果它们有帮助的话:

System.Runtime.InteropServices.COMException occurred
  _HResult=-2003304445
  _message=Exception from HRESULT: 0x88980003
  HResult=-2003304445
  IsTransient=false
  Message=Exception from HRESULT: 0x88980003
  Source=PresentationCore
  ErrorCode=-2003304445
  StackTrace:
       at System.Windows.Media.Imaging.RenderTargetBitmap.CopyCommon(RenderTargetBitmap sourceBitmap)
InnerException: 

在“异常帮助器”对话框的底部有一个链接,上面写着“将异常详细信息复制到剪贴板”。那样做。然后把它添加到你的问题中。我对此表示怀疑,但也许这让问题变得更清楚了?我认为这是因为gif很长,它有很多层,乘以50,你有很多层。我已经搜索了如何将这些gif组合成一个大gif,但对于gif来说,这似乎非常非常复杂