The notifyicon image looks awful as soon as the image gets into the system tray

I am using Visual Studio 2010, C #, on Windows 7.

I added a notification control to my project and set it to the icon that I imported into the project. The icon image really looks good if I just look at it, but as soon as I run my code and see it in the system tray, it is really terrible, because the sides are dotted instead of straight lines and so on. I tried 16x16, 24x24, 32x32 and 48x48 of the same file, but I have terrible results.

Did I miss something?

myNotifyIcon.Icon = SysDir.Properties.Resources.icon2_32_ico_rgba; 
+6
source share
2 answers

Edit:

At the moment, the information I'm linking seems suspicious. Try it, but if it doesnโ€™t work, I suggest you edit your question to post screenshots of all your experiments (each icon size and how it scales).

Original:

32x32x256 is the desired size and color depth at this link:

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

But when building this image you have to be very careful:

  • Take the image 16x16x256 and get it to look beautiful
  • Move it to 32x32 (careful not to blur or re-scale if this is done in a paint program)

The reason is that Windows will โ€œresizeโ€ the 32x32 image to 16x16 just by throwing 3/4 pixels. The link above demonstrates this phenomenon with a few screenshots:

Before:

Before shrinking icon

After:

After shrinking icon

I'm not sure how much of color intelligibility (only 256 colors)? / Re-sampling problems are still true for Windows 7, but it certainly looks like XP.

+5
source

The problem with using the icon directly in your resources is that instead of choosing the correct version of the icon in your icon file, the infrastructure simply scales the default version of the icon regardless of the size of the notification area. That is why you see jagged edges.

To get the best quality, you will need to choose the right size in your badge yourself.

First, instead of directly NotifyIcon.Icon your NotifyIcon.Icon to an icon in your resources, create a new instance of Icon . This will allow you to select a specific icon size in the icon resource. Using SystemInformation.SmallIconSize , you will get the size needed for the notification area.

So:

 myNotifyIcon.Icon = new Icon(Properties.Resources.MyIcon, SystemInformation.SmallIconSize); 

Now SystemInformation.SmallIconSize always returns the correct icon size, but only if your application supports DPI (otherwise it always returns 16). If your application does not support DPI, and it is used in a system where DPI scaling is enabled, the line above will select the 16x16 icon in your resource, while it will scale to any size that is required for the notification area (in other words, the ugly icon )

By providing your DPI community with an application, SystemInformation.SmallIconSize will return the correct size given DPI scaling. For example, if the DPI scaling is 150%, SystemInformation.SmallIconSize will return 24 (16 ร— 1.5).

For your application to recognize DPI, just add it to your app.manifest inside the <asmv1:assembly> :

  <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" > <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"> <dpiAware>true</dpiAware> </asmv3:windowsSettings> </asmv3:application> 
+12
source

Source: https://habr.com/ru/post/897710/


All Articles