SystemTrayIcon blurred

After changing the resolution of the screen (Windows OS), the tray icon is blurred.

Icons of other programs also have this problem, so it seems to be more of a windows issue. BUT: There are manufacturers/programs that have solved the problem.

As can be seen from the Juce documentation, only a juce::Image can be set as IconImage - so only pixel graphics.

Is there an approach to solve this problem?

First, this article provides useful background, as it explains What Icon Sizes Are Used by Windows. As you will gather from the article, the tray icon may not be the only one you will want to ensure looks good.

How to fix this is different in JUCE than if you were writing a Windows-specific program. In Windows programs, icons are specified as ICO files. In the ICO format, it is possible to embed multiple icon images, usually of the same subject but at different resolutions, in one file. Ideally, you would include several sizes, though Windows will use the nearest size for the purpose if you don’t include the exact size. The article explains which sizes are used for what purposes.

But, so far as I could tell, JUCE does not support the ICO format, presumably because it is Windows only (macOS’s native icon format is ICNS). So you have to use an ordinary pixel graphic format, as you say, such as PNG.

In Projucer, the Visual Studio settings allow Icon (Small) and Icon (Large) to be specified. If I recall correctly, you can do the same thing in code, which looks like what you have been investigating. I’ve tried both Icon (Small) and Icon (Large) and could not get Icon (Small) to do anything. So, if my experience is anything to go by, forget Icon (Small); you can only specify one image file for the icon, and it has to go in Icon (Large).

So here’s what I did when selecting an icon for what is so far my one and only JUCE program:

  • I picked a 512x512 pixel icon, one size larger than 256x256, the largest size used by Windows.
  • I made sure the one I picked was quite simple, so that it would still look OK when automatically shrunk by the operating system for display in various contexts, such as the system tray.
  • I edited the oversized icon down to 256x256, cropping the image so that the object in the image (i.e. what is in front of the background) goes right to the edge of the image, i.e. with no margins. If you don’t do that, the object may look unnecessarily tiny at small image sizes.

It worked very well. I checked how my icon looked in Windows, in the various contexts explained in the article. In all cases, it looks fine.

1 Like