使用 py2exe 在 .exe 中嵌入图标,在 Vista 中可见?
我一直在尝试使用 py2exe 将图标(.ico)嵌入到我的“编译”.exe 中。
Py2Exe 确实有一种嵌入图标的方法:
windows=[{
'script':'MyScript.py',
'icon_resources':[(1,'MyIcon.ico')]
}]
这就是我正在使用的。 该图标在 Windows XP 或更低版本上显示正常,但在 Vista 上根本不显示。 我想这是因为新的 Vista 图标格式,它可以是 PNG 格式,最大为 256x256 像素。
那么,如何让 py2exe 将它们嵌入到我的可执行文件中,而不破坏 Windows XP 上的图标呢?
我很乐意使用外部实用程序而不是 py2exe 来完成此操作 - 我已经尝试过 这个命令-line 实用程序 来嵌入它,但它总是会损坏我的 exe 并由于某种原因截断其大小。
I've been trying to embed an icon (.ico) into my "compyled" .exe with py2exe.
Py2Exe does have a way to embed an icon:
windows=[{
'script':'MyScript.py',
'icon_resources':[(1,'MyIcon.ico')]
}]
And that's what I am using. The icon shows up fine on Windows XP or lower, but doesn't show at all on Vista. I suppose this is because of the new Vista icon format, which can be in PNG format, up to 256x256 pixels.
So, how can I get py2exe to embed them into my executable, without breaking the icons on Windows XP?
I'm cool with doing it with an external utility rather than py2exe - I've tried this command-line utility to embed it, but it always corrupts my exe and truncates its size for some reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Vista 使用高分辨率256x256像素图像的图标,它们使用基于PNG的压缩来存储。 问题是,如果您只是制作图标并将其保存为标准 XP
ICO
格式,则磁盘上生成的文件将为400Kb
。 解决方案是压缩图像。 使用的压缩方案是PNG
(便携式网络图形),因为它具有良好的无损比并支持alpha通道。并使用
它从 1 个或多个
PNG
创建一个ICO
文件并处理多种尺寸等。我想 XP 不会有任何问题。Vista uses icons of high resolution 256x256 pixels images, they are stored using PNG-based compression. The problem is if you simply make the icon and save it in standard XP
ICO
format, the resulting file will be400Kb
on disk. The solution is to compress the images. The compression scheme used isPNG
(Portable Network Graphic) because it has a good lossless ratio and supports alpha channel.And use
It creates an
ICO
file from 1 or morePNG
's and handles multiple sizes etc. And I guess XP would have no problem with that.正如 Helmut 所说,图标大小的顺序似乎是关键。
反转页面(首先是较大的页面)可以解决 Windows 7 上“include_resources”的问题(使用 Py2exe 0.6.9)。
It seems that the order of icon sizes is the key, as said by Helmut.
To invert the pages (larger ones first) solves the issue on Windows 7 for 'include_resources' (using Py2exe 0.6.9).
我在使用包含 32x32 像素图像的 .ico 文件在 Windows7 上使用 py2exe 嵌入图标资源时遇到问题。 我使用了与原始问题相同的方法。
编译后,exe 上的图标消失。 根据 Resource Hacker 工具,经过调查,图标被添加到索引 0 处,但是如果我使用相同的工具来替换它添加在索引 1 处的图标。一旦到达索引 1,该图标就会再次神奇地出现在资源管理器中的 exe 旁边。
如果绝望,您可以使用 Resource Hacker 修改 exe 构建后,并且可以通过命令行界面编写脚本,但我尝试了上面解释的方法,并在像这样反转 png 文件后设法让它工作。
顺便说一句,通过向 ico 文件添加多个图标,您无论如何都会填充图标索引 1 处的资源,在本例中为 myico248x248.png。
I was having problems with embedding the icon resource with py2exe on Windows7 using a .ico file containing a 32x32 pixel image. I was using the same method as the original question.
Once compiled the icon on the exe disappears. On investigation the icon is added at index 0, according to the Resource Hacker tool, but if I use the same tool to replace the icon it is added at index 1. Once at index 1 the icon magically appears in explorer against the exe again.
If desperate, you could use Resource Hacker to amend the exe post-build and it can be scripted via the command line interface but I tried the method explained above and managed to get it to work after reversing the png files like so.
By the way by adding multiple icons to the ico file you are then populating the resource at icon index 1 anyway, in this case myico248x248.png.
Greenfish Iceon Editor Pro 的链接已损坏。
我扫描了网络并发现下载IcoFX
在我的 .exe 文件上使用 IcoFX 程序,可以看到它确实包含我的图标。
使用菜单“图像”->“从图像创建 Windows 图标”,然后接受选择,我得到了一个新的 .ico 文件,该文件适用于 win7 和 win xp。
在此之前,我的单个 48x48.ico 文件并未显示为程序的图标。
The link to the Greenfish Iceon Editor Pro is broken.
I scanned the net and found Download IcoFX
Used the IcoFX program on my .exe file and could see that indeed it contained my icon.
Using the menu Image->Create Windows Icons from Image, and then accepting the choices I got a new .ico file that worked on both win7 and win xp.
Before that my single 48x48.ico file just didn't show up as an icon for the program.