Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF BitmapImage Exception "The image data generated an overflow during processing"

I'm dealing with a very weird problem in WPF which only happens on ONE computer so far. The app in question has been installed hundreds of times, so I suspect missing dependencies of some sort, although this is a .NET Core 3.1 app.

So the app downloads icon images and the view binds to the icon via an exposed property in the ViewModel:

IconImage = new BitmapImage();
IconImage.BeginInit();
IconImage.UriSource = new Uri("LocalFilePath");
IconImage.DecodePixelWidth = 50;
IconImage.EndInit();

Where LocalFilePath is the path to the cached icon image. The image is a PNG file, it's size is 50x50 px.

The code above failes with an exception:

Message -> The image data generated an overflow during processing.
Source ->PresentationCore
 Trace ->    at System.Windows.Media.Imaging.ColorConvertedBitmap.FinalizeCreation()
   at System.Windows.Media.Imaging.ColorConvertedBitmap..ctor(BitmapSource source, ColorContext sourceColorContext, ColorContext destinationColorContext, PixelFormat format)
   at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
   at System.Windows.Media.Imaging.BitmapImage.EndInit()
InnerException -> Overflow or underflow in the arithmetic operation

What baffles me is that this only happens on one computer, running Windows 10 Home Edition with the latest updates. Has anyone seen this error before? Might there be a better, alternative way for exposing PNG images for the view?

like image 610
29Palms Avatar asked Aug 20 '20 17:08

29Palms


1 Answers

A few of our customers got the same error message recently. To fix this, we made sure that all settings in the color management window are "system default". In one instance, "device profile" was set to "virtual SRGB" which caused this issue.

It may also help to set IgnoreColorProfile in BitmapImage.CreateOptions.

Windows Color Management

like image 82
floele Avatar answered Nov 13 '22 09:11

floele