Reputation: 11754
I got an exception in my WPF window constructor on call : "InitializeComponent()"
The exception is NotSupportedException : "pixel format not supported"
I didn't find any info on the internet.
Why this exception ?
Upvotes: 2
Views: 3189
Reputation: 4664
Tracked this exception down to a PNG image in my application. After examining the image in Photoshop, I noticed that it had its color Mode set to Indexed. Changing it to RGB fixed the problem, and no more exceptions. You can check/change the mode in Photoshop as following:
Image -> Mode -> RGB
Also, this exception will only happen if you enable it in Visual Studio:
Debug -> Exceptions -> Common Language Runtime Exceptions (check)
Upvotes: 1
Reputation: 26
One potential cause for the "pixel format not supported" exception is an image with color space "Indexed". This means that a pixel value is not represented by three (R,G,B) bytes (which would be the case in the usual RGB color space), but by a single-byte index into a color table. The color space of an image can be checked and changed e.g. with Gimp via the "Image /Mode" menu.
Upvotes: 1
Reputation: 11754
I would like to let people know that the bug come from a buggy PNG image file used in a MenuItem.
To solve my problem I open the failing PNG in Paint.net and overide the buggy one.... No more exception.
Note: The problem appears only when you break on any exception. Otherwise everything seems ok and the icon (.png) show properly on the screen.
Upvotes: 4