11

I have a WPF application which runs fine on Windows 7 OS. But the same app crashes on a particular few Windows XP machines.

It runs fine on few windows XP machine. but on a few XP machine it fails to start.

ERROR - Image format is unrecognized.

I know this question has been asked few times. but my problem is i am still not able to figure out as to how to resolve this.

Should I change the .ico used for the application ..

0

5 Answers 5

10

Unfortunately, simply removing the 256x256 application isn't the greatest solution when you want to support the large icon size for Windows Vista, 7, 8 and forward.

Another way to solve this problem ... is to not compress the 256x256 image in the icon. See this forum thread for more info.

How does one do that? Well, most icon utilities will have an option for this (as this is a common problem). I use IcoFX and below you can see the option (highlighted in red) I needed to clear.

IcoFX Screenshot

3
  • My thanks to this post (stackoverflow.com/questions/8971751/…) which had an answer with the forum link in it ... which was the original inspiration/solution.
    – cplotts
    Nov 14, 2013 at 17:57
  • 1
    The compression makes a big difference, my icon went from 39kb to 288kb.
    – tofutim
    Feb 24, 2014 at 18:42
  • @tofutim, yes that is correct .. but that is necessary if you want to support Windows XP.
    – cplotts
    Feb 25, 2014 at 2:29
7

I've had a bit of fun with this problem this morning. It turned out that the error was occurring only on XP machines where the colour settings were set to 16 bit, and when I changed it to 32-bit the problem magically disappeared.

This goes for XP (including Embedded) SP3.

1
  • +1 Good observation.You saved my day :) . This help me figure out that RDP session with 16bit color caused my application to crash although I was able to launch it from VNC Session which had 32 bit color.
    – kiran
    Oct 14, 2014 at 8:52
4

In your WPF application you will have at least two places to set icons:

  1. The application icon. This is used for displaying the application in Explorer, desktop, etc. You set this in the project properties.
  2. The window icon. This is used as icon in the upper-left corner of the window, and perhaps for alt-tabbing and on the taskbar. You set this as the Icon property on the window.

Often, you may use the same icon file in both cases. However, if you have a compressed 256x256 icon as window icon, then this can crash in Windows XP. This is what you are experiencing. On the other hand, this not the case when the application icon has a compressed 256x256 icon.

So another solution (which I implemented in all my projects) is to have two icons: The application icon (which contains all sizes) and a special "window icon" version, which only contains the sizes 16x16 and 32x32 (since those are the only sizes which are used).

3

If I remember correctly Windows XP does not support icons larger than 48x48 pixels and this could be the reason for the crash. .ico files should definitely run on both systems.

You can create an icon that support multiple sizes, so if you add 48x48 and for example 256x256 in the same file you should be good. Also be sure to use select a good software to produce the icon when making icons that support multiple sized. I've used Greenfish Icon Editor which I think works fine. But there are multitudes of other products for this.

Be sure to read The ICON handbook, section Windows, it contains good info about what icon sizes and bit depths to use.


Other threads on SO supports my belief:

problems with icon image

Which icon sizes should my Windows application's icon include?

3
  • thanks @Avada Kedavra .. but it runs absolutely fine on few machines.. has it got something to do with resolution ?
    – Sandepku
    Sep 12, 2012 at 9:45
  • resolution.. it sounds far-fetched. but i dont really know. Sep 12, 2012 at 9:50
  • the bug was with an icon of 256X256.. it now works fine.. thanks for the links.. appreciate that..
    – Sandepku
    Sep 17, 2012 at 5:54
1

Another workaround to (16/32bit resolution problem) is not to define icon in XAML, but load it in code:

 this.Icon = new BitmapImage(new Uri("pack://application:,,,/UserInterface;component/Resources/Icons/ReportViewer.ico"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.