8

为什么这个特定的图像会导致我的应用程序因 OutOfMemoryException 而崩溃?

在此处输入图像描述

我用一个简单的窗口创建了一个非常简单的 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()
4

1 回答 1

1

据我所知,您的问题对应于 WPF 中一个已知但当前未确认的错误,请参阅Microsoft Connect。有趣的是,该问题已被标记为重复,但是我无法找到其他问题。如果它只是内部的,我不会感到惊讶......

解决方法

如果您的问题确实与上述错误有关,那么有一个简单的解决方法:只需将基于调色板的 PNG8 转换为非基于调色板的 PNG24。这可以使用 Photoshop 或 GIMP 来完成。

于 2014-06-04T09:43:46.633 回答