Skip to content

bug: when windows build is given an icon, only 16x16 icon is used #6007

@arthur-tacca

Description

@arthur-tacca

The problem

(For those that don't know, on Windows, a single icon can contain multiple different image sizes. Typically this is used to provide optimised images at smaller sizes that look better than downsampling larger sizes. Windows documentation says "Apps should have, at the bare minimum: 16x16, 24x24, 32x32, 48x48, and 256x256.")

If you supply a single Windows icon to flet build (by creating assets/icon_windows.ico) with a variety of icon sizes in it, then only the 16x16 (or presumably whichever is smallest) is used. This looks blurry and bad on the window corner (if you have scaling >100%) and on the taskbar button. To make this really obvious, I made an icon where each size has different text (of course my real icon is the same picture just at different sizes):

Image

I put this as assets\icon_windows.ico, and to avoid confusion I didn't put any other files in there. I then run flet build windows and then flet run. This is what I see in the taskbar - clearly using the 16x16 icon even though there are better suited sizes in the same .ico file:

Image

For comparison, I hacked the resulting .exe to put back the original .ico file that I made and re-ran, and sure enough it chose an appropriate size icon for the taskbar:

Image

The cause (partial investigation)

So what's going on in the .exe file? I had a look and it has one icon in it, and it does have multiple images in it. At first glance, they're the same as the original .ico file I supplied:

Image

Do you see the issue? It took me a while. They have all been resized to 256x256! The Flet docs say that the icon file is copied unmodified, but clearly something is fiddling with the images within the icon.

I tried to look a little deeper but I couldn't figure out where exactly in the Flet code this is happening. I did find that app_icon.ico (in .\build\flutter\windows\runner\resources) already has the problem with modified images, so the change happens before that point. But I couldn't see where that file is made.

Why am I doing this? (another problem)

Why bother having an icon with multiple sizes? The truth is, I am not making hand-optimised little icons. I'm just taking the larger size and shrinking it. So why not provide one large image to Flet and let it sort it out? The answer is: because that looks bad too! It seems to be a combination of two problems:

  • If you supply a large icon image (i.e. icon.png or icon_windows.png) to Flet, it creates an icon with only one size in it - 256x256
  • When Windows needs an icon image and there isn't one the right size, it takes the next largest one and resizes it using nearest neighbor (not something better like bicubic).

As a result, the taskbar icon is resized directly down from 256x256 to a smaller size for the taskbar and window icon (the exact size depends on your screenscaling) with only nearest-neighbor scaling, which looks terrible for an image that's just slightly complex.

If Flet were to convert a single source image to an icon with a proper selection of icon image sizes (typically 16, 24, 32, 48, 64, 128 and 256 pixels squared), with proper downsampling, then many people wouldn't need to manually supply their own .ico file in the first place.

My overall workaround

In case someone else needs it: for now, my workaround is to supply a single image to Flet, already downsampled to 48x48. That means that nearest neighbor at smaller sizes looks less poor than going all the way down from 256x256, and hopefully it's rare that a larger size will be shown.

Versions

Operating System: Windows 11

Flet version: Tried with both 0.28.3 and 0.80.1

Regression: No, it isn't

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions