简体   繁体   English

托盘图标看起来不错,但WPF Window图标看起来很糟糕

[英]Tray icon looks fine but WPF Window icon looks horrible

Is there any way to force a WPF Window to scale an icon down to a size with a better algorithm for the scaling or force it to use better resolutions for my icon? 是否有任何方法可以强制WPF窗口将图标缩小到具有更好的缩放算法的大小,或者强制它为我的图标使用更好的分辨率?

I made an icon (ICO-format) file that hosts a 256x256, 32 bit, PNG image. 我制作了一个图标(ICO格式)文件,其中包含一个256x256,32位PNG图像。 I set my project's icon to this one in the project's properties. 我在项目的属性中将项目的图标设置为此图标。 It looks fantastic in the Windows tray when I run the application. 当我运行应用程序时,它在Windows托盘中看起来很棒。

The problem is when I set the icon to the Window in question. 问题是当我将图标设置为有问题的窗口时。 What happens is...it doesn't down-scale my image properly and I get this ugly image at the top left of my Window with some bad anti-aliasing on it. 会发生什么......它没有正确缩小我的图像,我在窗口的左上角看到了这个丑陋的图像,并且有一些不好的抗锯齿。 Its not smooth at all. 它根本不光滑。 What can I do? 我能做什么?

You have one of two problems: WPF downscales icons poorly (jagged/skewed), or icons are rendered poorly (blurry) 你有两个问题之一:WPF缩小图标很差(锯齿/歪斜),或图标渲染效果不佳(模糊)

To solve the first one, I would not rely on WPF to downscale icons. 要解决第一个问题,我不会依赖WPF来缩小图标。 Use GIMP or Photoshop to create the icon in 16, 32, 64, 128 and 256 dimensions, and save them in separate folders: 使用GIMP或Photoshop在16,32,64,128和256维度中创建图标,并将它们保存在单独的文件夹中:

Icons
  16
    MyIcon.png
    AnotherIcon.png
  32
    MyIcon.png
    AnotherIcon.png
etc.

Most icon libraries come in multiple sizes (IconExperience, Syncfuction, etc.). 大多数图标库有多种尺寸(IconExperience,Syncfuction等)。 If you create a custom icon, you should downscale it yourself to have full control. 如果您创建自定义图标,则应自行缩小图标以完全控制。

You can create custom controls that help you find the right icon. 您可以创建自定义控件,以帮助您找到正确的图标。 So you can define in one common place which size icon you want to use where: 因此,您可以在一个常见位置定义要使用的大小图标:

<CustomIcon Name="MyIcon.png" Location="Ribbon"/>

Where Name is the filename, and Location is a selfdefined enum that allows you to predefine the sizes based on their location in the UI. 其中Name是文件名,Location是自定义的枚举,允许您根据UI中的位置预定义大小。 The CustomIcon could inherit from Image, and internally set the Source based on these two properties. CustomIcon可以从Image继承,并根据这两个属性在内部设置Source。

If you think are experiencing the second issue, try setting UseLayoutRouding="True" on your MainWindow, aad experiment with RenderOptions.BitmapScalingMode (WPF4 and onwards). 如果您认为遇到第二个问题,请尝试在MainWindow上设置UseLayoutRouding =“True”,并尝试使用RenderOptions.BitmapScalingMode(WPF4及以后版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM