如何在不增加可执行文件大小太多的情况下将图像添加到桌面应用程序中?
我正在构建一个桌面应用程序,偶尔会向解决方案资源管理器添加图像。当我“构建”应用程序时,我注意到 .exe 文件的大小增加了。如果我添加 40kb 的图像,.exe 会增加 40kb。
总而言之,我的应用程序目前有 12mb,我认为对于人们来说下载有点太多了。
有没有办法最小化 .exe 大小,换句话说,将图像添加到我的应用程序中,同时对大小影响最小?
I'm building a desktop application and I occasionally add images to the solution explorer. When I "Build" the application, I notice the .exe file increases in size. If I add an image that's 40kb, the .exe increases 40kb.
All in all, my application is currently 12mb, and I think it's a bit too much for people to download.
Is there a way for me to minimize the .exe size, in other words, add images to my application with minimal size impact?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将图像外部化,将它们作为单独的文件传送,或者让您的应用程序从 Web 服务器下载它们。 WPF 很乐意使用 HTTP 或文件系统 URL 作为 Image 元素的源。
但这只是转移了问题:您最初的 EXE 较小,但现在还有一堆其他文件需要下载。归根结底是:如果您有 12 MB 的图像,那么您就有 12 MB 的图像,而这 12 MB 必须以某种方式到达用户的计算机!
如果您担心 12 MB 的应用程序大小,您可以尝试缩小文件 - 较低的分辨率、不同的文件格式(例如 JPG 而不是 BMP)等。或者,如果用户不需要所有文件对于文件,您可以让应用程序按需下载它们(但请注意,如果用户离线,这可能会造成延迟或错误)。
另一方面,按照现代标准,12 MB 对于游戏类型应用程序来说实际上并不是那么大(据我所知,您的应用程序是这样的)。因此,除非您的目标市场中有许多用户仍然使用拨号或其他缓慢或较差的连接,否则这可能没什么大不了的。
You can externalise the images, shipping them as separate files or having your app download them from a Web server. WPF is happy to use a HTTP or file system URL as the Source for an Image element.
But this just shifts the problem: your initial EXE is smaller, but now there's a bunch of other files to download as well. What it comes down to is: if you've got 12 MB of images, you've got 12 MB of images, and those 12 MB have got to get to the user's machine somehow!
If you're concerned about a 12 MB application size, you could try to make the files smaller -- lower resolution, different file format (e.g. JPG instead of BMP), etc. Or, if the user isn't going to need all of the files, you could have the app download them on demand (but note this could create delays, or errors if the user is offline).
On the other hand, by modern standards, 12 MB really isn't all that enormous for a game-type application (which is what I understand yours to be). So unless you're targeting a market where a lot of users are still on dial-up or other slow or poor connections, it may not be that big a deal.
这实际上取决于您的图像,但是...如果它们彼此有些相似,您可以将它们压缩起来,然后在安装时或应用程序第一次运行时展开。无论如何,你都可以尝试压缩,看看会发生什么。如果您可以将图像减少 20% 或更多,那么压缩可能是值得的。 (或者您可以故意选择相似的图像来帮助压缩。)
此外,如果您的图像很简单,您可以尝试 GIF 格式。它非常擅长压缩带有线条和更简单的颜色字段的图像(例如非摄影图像......更像动漫)
顺便说一句,我也喜欢 itowlson 的答案。 +1
It really depends on your images but... if they're somewhat similar to each other you could zip them up and then expand at install or the first time the app runs. You could try zipping anyway just to see what happens. If you can reduce the images by 20% or more zipping might be worth it. (Or you could choose images that are similar on purpose to help out the zipping.)
Also, if your images are simple you could try the GIF format. It's very good at compressing images with lines and simpler fields of color (e.g. non-photographic images... more like Anime)
i also like itowlson's answer btw. +1
我刚刚对编译 exe 文件大小进行了快速测试。如果将文件作为资源添加到解决方案资源管理器,这些图像将直接编译到 exe 中。但是,如果您只是将文件添加到解决方案资源管理器,并为该文件指定“Conten”的“构建操作”和“如果较新则复制”的“复制到输出目录”,则该文件不是 exe 的一部分,而是一个exe 旁边的辅助文件。
这意味着该映像可供您的 exe 使用,但不是它的一部分。
这可能就是您正在寻找的,因为它允许您轻松更改应用程序中使用的图像[只需在解决方案文件夹中更改它们]
I just did a quick test of compile exe file sizes. If you add files to the solution explorer as a Resource, these images are compiled directly into the exe. However if you just add the file to the solution explorer and give the file a 'build action' of "Conten" and a 'copy to output directory' of "copy if newer" then the file isnt part of the exe, but is a secondary file alongside the exe.
This then means the image is availiable to your exe but is not part of it.
This might be what you are looking as it allows you to change the images used in the application easily [by just changing them in the solution folder]