wpf WPF应用程序中的任务栏丑陋的图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12901212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 05:47:23  来源:igfitidea点击:

Taskbar ugly icon in WPF application

wpficons

提问by Developer

The icon in the taskbar is looking very ugly in my WPF application.

任务栏中的图标在我的 WPF 应用程序中看起来非常难看。

The designer sent me some PNGs like:

设计师给我发了一些 PNG,例如:

32x32, 64x64, 96x96, 128x128, 192x192, 256x256, 512x512.

32x32、64x64、96x96、128x128、192x192、256x256、512x512。

What do I have to do to get the goodloking taskbar icon?

我该怎么做才能获得可爱的任务栏图标?

Thank you!

谢谢!

回答by Stephen Booher

Make an .ico file containing multiple sizes. At a minimum, you should have the following sizes: 16x16, 32x32, 48x48, and 256x256 according to the Windows icon visual guidelines. Having a single .ico file will help Windows pick the best size and scale it appropriately depending on the situation (application icon, large taskbar, small taskbar, etc.)

制作一个包含多种尺寸的 .ico 文件。根据Windows 图标视觉指南,您至少应具有以下尺寸:16x16、32x32、48x48 和 256x256 。拥有单个 .ico 文件将帮助 Windows 选择最佳大小并根据情况(应用程序图标、大任务栏、小任务栏等)适当缩放

If you aren't a designer, then it's also better to let your designer make the 16x16 image, since it's possible the larger images you have have too much detail and do not scale down very well. If the larger images are very detailed, then the designer could make the smaller images simpler so that the icon shows better. The visual guidelines linked above have more tips about this.

如果您不是设计师,那么最好让您的设计师制作 16x16 图像,因为您拥有的较大图像可能有太多细节并且无法很好地缩小。如果较大的图像非常详细,那么设计师可以使较小的图像更简单,以便更好地显示图标。上面链接的视觉指南对此有更多提示。

回答by Hannish

I had the same problem, it was not working even with a multi-sized .ico file. Setting the icon directly in the Window resulted in a pixelated icon.

我遇到了同样的问题,即使使用多大小的 .ico 文件也无法正常工作。直接在窗口中设置图标会导致像素化图标。

I managed to fix it with this code-behind for the application window:

我设法使用此应用程序窗口的代码隐藏来修复它:

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Uri iconUri = new Uri("pack://application:,,,/Images/myicon.ico", UriKind.RelativeOrAbsolute); //make sure your path is correct, and the icon set as Resource
        this.Icon = BitmapFrame.Create(iconUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

        //etc.
    }

Icon file is multi-sized, this worked for me in WPF - Windows 10.

图标文件是多尺寸的,这在 WPF-Windows 10 中对我有用。

You can convert your .png icon into a multi-sized .ico file here http://icoconvert.com/

您可以在此处将 .png 图标转换为多尺寸的 .ico 文件http://icoconvert.com/

回答by Joe Bloe

Taskbar icons seem to get blurry as soon as a 48x48 pixels version is included in the .ico file. Instead of picking the correctly sized 32x32 pixels version, for some reason Windows apparently picks the 48x48 one and scales it down.

一旦 .ico 文件中包含 48x48 像素版本,任务栏图标似乎就会变得模糊。出于某种原因,Windows 没有选择正确大小的 32x32 像素版本,而是选择了 48x48 版本并将其缩小。

The solution for me is to use two separate icon files:

我的解决方案是使用两个单独的图标文件:

  • One .ico containing 24x24 and 32x32 versions of the icon, which will, when set as a Window's icon using the Iconproperty in XAML or Hannish's approach, be used for the titlebar and taskbar respectively - withoutunwanted scaling.
  • A second icon file containing - depending on which sources are right - a range of sizes between 16x16 and 256x256 pixels. Setting this one as the application icon in the project properties will make the icon look good in all the other places like the desktop and the file explorer on different view settings.
  • 一个 .ico 包含 24x24 和 32x32 版本的图标,当使用IconXAML 或 Hannish 方法中的属性将其设置为窗口图标时,将分别用于标题栏和任务栏 -没有不必要的缩放。
  • 第二个图标文件包含 - 取决于哪些来源是正确的 - 大小介于 16x16 和 256x256 像素之间。将此图标设置为项目属性中的应用程序图标将使图标在所有其他位置(如桌面和文件资源管理器)在不同视图设置中看起来都不错。

Testing on Windows 10, this seems to cover the following display cases: taskbar, window titlebar, Alt-TAB menu, Desktop and file explorer.

在 Windows 10 上测试,这似乎涵盖了以下显示案例:任务栏、窗口标题栏、Alt-TAB 菜单、桌面和文件资源管理器。