c# – 仅在Windows 8.1中的BitmapImage OutOfMemoryException
我最近安装了
Windows 8.1来尝试,我的宠物项目正在崩溃(同样的二进制文件在一台Win7和两台Win8机器上工作正常).
在BitmapImage.EndInit中抛出OutOfMemoryException: public static BitmapImage GetResourceImage(string resourcePath,int decodePixelWidth = 0,int decodePixelHeight = 0) { var image = new BitmapImage(); var moduleName = Assembly.GetExecutingAssembly().GetName().Name; var resourceLocation = string.Format("pack://application:,/{0};component/Resources/{1}",moduleName,resourcePath); image.BeginInit(); image.UriSource = new Uri(resourceLocation); image.DecodePixelWidth = decodePixelWidth; image.DecodePixelHeight = decodePixelHeight; image.EndInit(); image.Freeze(); return image; } >崩溃过程的任务管理器读数:27MB内存,302个句柄,12个线程,36个用户对象,34个GDI对象,5.3 GB RAM可用 据我通过谷歌搜索了解,它与GDI内部有关,但我找不到修复或解决方法.任何想法(除了使用一些其他机制来解码和/或调整图像大小 – 我只需要原始像素数据)? 完整的项目源代码可以在这里找到(链接到相关文件):https://code.google.com/p/lander-net/source/browse/trunk/csharp/LanderNet/Util/BitmapUtils.cs 更新: 解决方法
我创建了一个单独的项目并将问题隔离开来.
在GDI中看起来像一个非常奇怪的错误,有256个颜色的位图(我的所有图像都是从我在QBasic写的学校时代游戏中获得的256色位图). > png和24位位图没有问题 所以我的问题是通过将所有内容转换为PNG来解决的. 错误发布到Microsoft Connect:https://connect.microsoft.com/VisualStudio/feedback/details/812641/bitmapsource-fails-with-outofmemoryexception-on-8-bit-bitmaps 下面是代码. internal class Program { public static BitmapSource GetResourceImage(string resourcePath,resourcePath); image.BeginInit(); image.UriSource = new Uri(resourceLocation); image.DecodePixelWidth = decodePixelWidth; image.DecodePixelHeight = decodePixelHeight; image.EndInit(); image.Freeze(); return image; } private static void Main() { new Application(); // register pack uri scheme //GetResourceImage("Z40100.png"); //GetResourceImage("Z40100.bmp"); //GetResourceImage("Z40100_256color.bmp"); //GetResourceImage("Z40100_24bit.bmp"); // Uncomment the following line to fix the crash (or any of the two lines above) //GetResourceImage("Z40100_24bit.bmp",50,50); //GetResourceImage("Z40100_256color.bmp",50); GetResourceImage("Z40100.bmp",50); // GetResourceImage("Z40100.png",50); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |