简体   繁体   English

如何在不增加可执行文件大小的情况下将图像添加到桌面应用程序?

[英]How can I add images to my desktop application without increasing the executable file size too much?

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. 当我“构建”应用程序时,我注意到.exe文件的大小增加。 If I add an image that's 40kb, the .exe increases 40kb. 如果我添加40kb的图像,.exe增加40kb。

All in all, my application is currently 12mb, and I think it's a bit too much for people to download. 总而言之,我的应用程序目前是12mb,我认为这对人们下载来说有点太多了。

Is there a way for me to minimize the .exe size, in other words, add images to my application with minimal size impact? 有没有办法让我最小化.exe大小,换句话说,添加图像到我的应用程序,影响最小?

You can externalise the images, shipping them as separate files or having your app download them from a Web server. 您可以将图像外部化,将它们作为单独的文件发送,或让您的应用程序从Web服务器下载它们。 WPF is happy to use a HTTP or file system URL as the Source for an Image element. WPF很乐意使用HTTP或文件系统URL作为Image元素的Source。

But this just shifts the problem: your initial EXE is smaller, but now there's a bunch of other files to download as well. 但这只是改变了问题:你的初始EXE较小,但现在还有一堆其他文件要下载。 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 ! 它归结为:如果你有12 MB的图像,你有12 MB的图像,那12 MB必须以某种方式到达用户的机器!

If you're concerned about a 12 MB application size, you could try to make the files smaller -- lower resolution, different file format (eg 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). 如果您担心12 MB的应用程序大小,您可以尝试使文件更小 - 更低的分辨率,不同的文件格式(例如JPG而不是BMP)等。或者,如果用户不需要全部对于文件,您可以让应用程序按需下载它们(但请注意,如果用户处于脱机状态,可能会造成延迟或错误)。

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). 另一方面,按照现代标准,对于游戏类型的应用程序来说,12 MB实际上并不是那么大(这是我理解的)。 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. 因此,除非您的目标市场是许多用户仍然使用拨号或其他缓慢或差的连接,否则可能不是那么大的交易。

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. 如果你可以减少20%或更多的图像压缩可能是值得的。 (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. 此外,如果您的图像很简单,您可以尝试GIF格式。 It's very good at compressing images with lines and simpler fields of color (eg non-photographic images... more like Anime) 它非常适合用线条和更简单的颜色区域压缩图像(例如非摄影图像...更像动漫)

i also like itowlson's answer btw. 我也喜欢itowlson的答案顺便说一句。 +1 +1

I just did a quick test of compile exe file sizes. 我刚刚对编译exe文件大小进行了快速测试。 If you add files to the solution explorer as a Resource, these images are compiled directly into the exe. 如果将文件作为资源添加到解决方案资源管理器,则这些图像将直接编译到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. 但是,如果您只是将文件添加到解决方案资源管理器并为文件提供“构建操作”的“Conten”和“复制到输出目录”的“复制如果更新”,那么该文件不是exe的一部分,但是辅助文件与exe一起。

This then means the image is availiable to your exe but is not part of it. 这意味着图像可用于您的exe,但不是它的一部分。

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] 这可能就是您所看到的,因为它允许您轻松地更改应用程序中使用的图像[只需在解决方案文件夹中更改它们]

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

相关问题 在图像上添加徽标会使尺寸增加太多 - adding logo on image is increasing size too much 如何将图像添加到我的.resx文件中? - How can I add images into my .resx file? 如何将C#项目更新为可执行文件/应用程序? - How can I update my C# project as an executable file/application? 如何在桌面WPF应用程序中播放OGG声音文件? - How can I play a OGG sound file inside of my desktop WPF application? 如何从Windows CE移动设备访问文件到我的桌面应用程序? - How Can I access File from Windows CE mobile to my desktop application? 将图像和文本添加到我的测验应用程序(C#Desktop) - Add images and Text to my quiz application (C# Desktop) 我如何以编程方式向资源添加可执行文件(.exe)? - How i can add an executable file(.exe) to Resources programmatically? 如何使用可执行文件打开文本文件? - How can I open a text file with my executable? 如何在需要MDW文件时将Access DB添加到我的C#项目中? - How can I add an Access DB to my C# project when it requires an MDW file too? 我可以让我的WPF应用程序以120 FPS的速度播放图像序列而不用太多内存吗? - Can I get my WPF application to play an image sequence at 120 FPS without using so much memory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM