Tuesday, April 22, 2008

Icon size in notifyicon

Recently I had a requirement to create a windows service in .net. This service also had to have a "form" like a "dashboard" functionality that showed the status of the service and various options that the user could do to make changes to the service functions. For this, I decided to show a icon in the taskbar when the service starts and onclick of this icon, I would show the form.

This can be done using notifyicon control in .net and its pretty straightforward. But the issue I was facing was with the icon been shown in the taskbar. It was never clear and after trying various options like different size etc, i searched the net and found this article which was useful - http://www.hhhh.org/cloister/csharp/icons/

------ from the above link ------
"A reader asked for a quick-reference table at the top of this document, showing the default icon versions used by Windows Forms applications in different circumstances, so here it is. Detailed explanations are provided below if you're interested

Circumstance: Icon Version:
Control Box 16x16x256
Taskbar 16x16x256
Notify Icon 32x32x256, shrunk down (see below)
Desktop Shortcut 32x32x256 (Normal sized icons)
48x48x256 (Large sized icons)
Add/Remove Programs 16x16x256
Folder Browse dialog 16x16x256

Notify IconIf 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.

16x16 Notify Icon 18x18 Notify Icon


Notice that the text on my 32x32x256 icon is barely readable when shrunk down to 16x16 size. The same will be true for any one-pixel-wide details you include in your 32x32x256 bitmap, unless you are very careful about where you put them. The reason for this is clear: a 16x16 bitmap has only one-quarter as many pixels as a 32x32 bitmap. Consequently, three-quarters of the information in the 32x32 bitmap is thrown away when shrinking it down to 16x16. What to do about it is less clear.

To get a more optimal appearance for your NotifyIcon, you need to know which pixels out of the 32x32 bitmap are the ones that will be displayed at 16x16 size. Fortunately, the mapping is straightforward. Windows throws out all the even-numbered rows and columns, and keeps what's left. Shown here at double-size is a 32x32x256 bitmap, where the black pixels are the ones that will be seen when the bitmap is shrunk down to 16x16 on a NotifyIcon, and the actual NotifyIcon image that this bitmap turns into in the system tray:
Before: ...and after:
As you can see in these two images, the black pixels in the 32x32 image are the ones that are actually displayed at 16x16 size. The yellow has disappeared because the even-numbered rows and columns are thrown away. Pixels in the even-numbered rows and columns are important for the appearance of desktop shortcut icons, but are irrelevant for NotifyIcon objects.

1 comment:

  1. If you create an .ico file which just contains a 16x16 Icon, it will not get crunched but displayed as been created in 16x6 (eg. with IconWorkshop)

    ReplyDelete