开发者

Distorted System Tray Icons

I've written a little system开发者_C百科 tray application that uses a NotifyIcon to display the status of a process. I'm loading a high quality 64 by 64 png formatted icon in the following way:

Bitmap rawImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Snitch.Icons.Loading.png"));
m_icon.Icon = Icon.FromHandle(rawImage.GetHicon());  

However the icon that appears in the system tray never looks as good as my source icon, is there an setting or something I am missing? I've tried the 16x16, 32x32 eight bit icon files that VS2008 creates but they don't seem to fair any better.


If you add a NotifyIcon control to your application's Form object, then your application will display an icon in the tray area of the taskbar. The rendered size of the notify icon is the same as for the Control Box and Taskbar icons: 16x16 pixels, potentially stretched to accomodate the height of the system tray, which is dependent on the height of the Taskbar. Oddly, however, Windows does not use the 16x16x256 bitmap for this circumstance; it uses the 32x32x256 bitmap by default, and squashes it down to the required size. I can think of no particularly good reason for this difference--using the 32x32 version for the notify icon, but 16x16 for taskbar and control box--but there it is.

http://www.hhhh.org/cloister/csharp/icons/

Note - the article is from c. 2003


Consider the quality of a thumbnail image relative to a full-size photograph; now imagine shrinking the entire photo down to 16x16 pixels. The greater the discrepancy between the original size and the new size, the worse the result will look, no matter whether you're shrinking or stretching.

The best thing to do, if you can, is obtain or create an .ico file that actually contains separate 16x16, 32x32, 48x48 and 64x64 icons. The next best thing is probably to use a plain 16x16 icon for the notification area. Any image resizing/resampling is going to look distorted.

There are a number of sites on the web with free or inexpensive downloads of multiple-sized or 16x16 icons. There are already several questions here on where to find icons so I won't try to start listing sites myself.


I see distorted icons in my system tray, too, and I've traced the problem to Win DPI setting. In my case, it's 115 instead of 100. When shown in the system tray, a 16x16 icon is actually shown as 18x18. The number comes from this equation:

iconSize= (int) (16* (115/100))= int (18.4) = 18

The 18x18 icon looks ugly because Win takes a 16x16 icon and "clones" a few pixel rows and columns to match the new size. I've tried supplying Win with a custom 18x18 icon, but Win won't show it on the system tray as-is. It will first force the icon bitmap to the nearest power-of-2 size (16x16), and then stretch it to 18x18 for display by pixel-cloning (with expected artifacts). Other than changing your DPI, I don't see any workarounds, because we have no control over the forced, intermediate "power-of-2" step.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜