I know there are other questions about this already, but I couldn't find an answer to my problem in them.
I am pretty new to WPF and I am building media player which also includes displaying images. One of the options is to tile image. That is done like this:
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;
}
}
And for one specific gif image (3,13 MB 200 x 196), after function completes I am receiving. Image is small, but long and for 1920x1080 screen, this adds ~50 images.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
at System.Windows.Media.Imaging.RenderTargetBitmap.CopyCommon(RenderTargetBitmap sourceBitmap)
Image is small, but long and for 1920x1080 screen, this adds ~50 images.
I red that it's about too many GDI handles. With GDIView I can see that it has ~7000 region handles. Can someone tell me what is happening here and how to avoid this?
Edit: Okey, here are the exception details if they help:
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:
User contributions licensed under CC BY-SA 3.0