[英]How can I keep the size of a Delphi application small when it has many TImage components?
I want to make an application using Delphi. 我想用Delphi制作一个应用程序。 The problem is I am going to have a lot of
TImage
components in it - which will make the exe size extremely large. 问题是我将有很多
TImage
组件 - 这将使exe大小非常大。 So far my exe is 20MB large and I have only completed the home page, by my calculations the exe alone will be more than 10GB in size - which is way too much. 到目前为止,我的exe是20MB大,我只完成了主页,根据我的计算,exe单独的大小将超过10GB - 这太过分了。
How can I make an app with hundreds/thousands of images and yet let the exe be small in size? 如何制作具有数百/数千张图像的应用程序,同时让exe的尺寸变小?
Don't put the images in the executable. 不要将图像放在可执行文件中。 Keep them in external files and load them at runtime.
将它们保存在外部文件中并在运行时加载它们。
This will require you to stop loading the images into the TImage
controls at design-time and instead use dynamic code to load the image, and transfer to the TImage
control. 这将要求您在设计时停止将图像加载到
TImage
控件中,而是使用动态代码加载图像,然后传输到TImage
控件。 There are many advantages of doing so: 这样做有很多好处:
TImage
will persists to a .dfm file in a very inefficient way. TImage
将以非常低效的方式持久存在.dfm文件中。 You can choose to use PNG or JPEG compression. If you don't need to keep your images in their original size, you can read them in at program startup and scale them to their "working" size. 如果您不需要将图像保持原始大小,可以在程序启动时读取它们并将它们缩放到“工作”大小。 This will reduce your memory requirements immensely - for example, reducing an image to half its original width and height reduces memory requirements to a quarter of the original image.
这将极大地降低您的内存需求 - 例如,将图像缩小到原始宽度和高度的一半会将内存需求降低到原始图像的四分之一。
If the images don't change, you can do this offline in a separate build process and reduce the load time a lot too. 如果图像没有更改,您可以在单独的构建过程中脱机执行此操作,并减少加载时间。 Otherwise, you can cache the reduced images during the load process to speed it up the next time the program is started.
否则,您可以在加载过程中缓存缩小的图像,以便在下次启动程序时加快速度。
You might find the binary code includes all the images as PNG file format, so it will be compile extremely application size for you. 您可能会发现二进制代码包含所有图像为PNG文件格式,因此它将为您编译极其适用的应用程序。
I use the images in runtime, as JPG, so in the form's OnCreate
events you can load from the Package. 我在运行时使用图像作为JPG,因此在表单的
OnCreate
事件中,您可以从Package加载。
Use the "Project" Menu "Deployment" to include your JPG files to the APK. 使用“项目”菜单“部署”将您的JPG文件包含到APK。
You can read more here: http://blogs.embarcadero.com/davidi/2013/11/23/43005/ 你可以在这里阅读更多内容: http : //blogs.embarcadero.com/davidi/2013/11/23/43005/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.