2014-01-30 64 views
5

为什么这个特定的图像导致我的应用程序崩溃与OutOfMemoryException?为什么这个特定的图像会导致我的应用程序崩溃并导致OutOfMemoryException异常?

enter image description here

我创建了一个非常简单的WPF Windows应用程序有一个简单的窗口:

<Window x:Class="DeleteMe.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Image Source="C:\Path\To\The\Image\MyImage.png" RenderOptions.BitmapScalingMode="Fant"></Image> 
    </Grid> 
</Window> 
  • 如果是x86或x64没关系。
  • 如果我调整图像文件的大小,即使是1像素它的作品。
  • 如果我将几个像素添加到图像并保存它,它仍然不起作用。
  • 该问题仅在FantHighQuality位图缩放模式下发生。

这是一个问题的原因是我不想调整我们从创建这些图像的人获得的每个图像的大小。正如我所说,我正在使用Paint.Net处理图像。

谢谢。

我的事件查看器给了我下面的:

Application: DeleteMe.exe 
Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception. 
Exception Info: System.OutOfMemoryException 
Stack: 
    at System.Windows.Media.Composition.DUCE+Channel.SyncFlush() 
    at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean, System.Nullable`1 
<ChannelSet>) 
    at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr) 
    at System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr) 
    at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 
    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 
    at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) 
    at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 
    at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 
    at System.Windows.Threading.Dispatcher.Run() 
    at System.Windows.Application.RunDispatcher(System.Object) 
    at System.Windows.Application.RunInternal(System.Windows.Window) 
    at System.Windows.Application.Run(System.Windows.Window) 
    at System.Windows.Application.Run() 
    at DeleteMe.App.Main() 
+0

我记得早在.NET中,一些图像API会在加载格式不正确的图像时抛出OOM。这不是一个致命的进程崩溃OOM,只是一个“嘿这张图片有一个不好的尺寸输入”OOM。也许这就是这里发生的事情。只是尝试直接加载图像,看看是否工作或投掷 – JaredPar

+0

伸手可及但在项目中尝试图像 – Paparazzi

+2

当我添加与上述相同的XAML时,这不是炸毁我。在代码隐藏方面有什么?你的图形驱动程序是最新的吗? – Matt

回答

0

至于我可以告诉你的问题相当于WPF已知,但目前未经证实的错误,看到Microsoft Connect。有趣的是,这个问题已被标记为重复,但我无法找到其他问题。我不会感到惊讶,如果这是唯一的内部...

解决方法

如果您的问题真的被连接到上面的错误,然后有一个简单的解决方法:只要你的基于调色板的PNG8转换为基于非调色板的PNG24。这可以通过例如使用Photoshop或GIMP。

相关问题