Application Size Increases When Setting Application Icon from Resources

回眸只為那壹抹淺笑 提交于 2019-12-23 10:11:20

问题


I have an application whose size is 16kb.

After adding an icon resource through the Project Properties menu, the application, as expected, increased to a size of 299kb.

Now, under Properties/Application when I set the Icon File to "Resource\IconName.ico" the file size again increases to 581kb.

Is this normal behavior? I understand that it increases when I add the icon as a resource, but not when I set the icon from the resources to the Application Icon.

Can anyone explain why this is happening?

EDIT:

Maybe a better question would be how can I set the Application Icon using an icon from the Properties/Resources section?


回答1:


Yes, this is normal behaviour. Your icon isn't being stored as a resource twice (as suggested in some comments), it's simply being linked into the exe during compilation while also being stored as a resource. Since the icon is public-facing (i.e. explorer.exe accesses it directly when rendering the icon), you essentially end up with 2 copies of the icon in different formats:

  • One copy of the icon compiled directly into the exe in a Windows-standard format
  • One copy as a .NET resource

If you really want to save this extra space, remove the embedded resource, change your application icon reference to point straight to the icon on disk, then, when you need a copy of the icon to assign to your forms, extract it directly from the assembly:

var executablePath = Assembly.GetExecutingAssembly().Location;
var icon = Icon.ExtractAssociatedIcon(executablePath);


来源:https://stackoverflow.com/questions/12030981/application-size-increases-when-setting-application-icon-from-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!