【问题标题】:How to improve the load time of Delphi TPngImageList (or TImageList)如何提高 Delphi TPngImageList(或 TImageList)的加载时间
【发布时间】:2010-10-28 09:24:05
【问题描述】:

我在我的应用程序中使用了一组大约 100 个图标,这些图标使用固定的参考编号进行访问,并且这些编号也可供用户选择图标。所需的三种分辨率是 16x16、32x32 和 48x48。这些分辨率中的每一个都保存在 TPngImageList 中,我使用 TDataModule 创建了一个“图标库”,而不是包含这三个图像列表 (TArtImageLibraryImageLists)。当需要任何图像列表时,一个简单的“首次使用时创建”方法会实例化此 TDataModule。任何需要访问图像列表的控件的 LargeImages 或类似属性只需调用所需的分辨率函数即可。

问题是程序启动时的加载时间,在快速机器上约为 1s。显然,最坏的罪魁祸首是 48x48 图像列表,但我想知道是否有更好的加载机制(例如使用资源文件?)可以加快速度。或者有没有办法重新格式化图像列表?我在运行时仍然需要一个 TImageList,例如用于我的 TreeView 等。

谢谢, 布赖恩。

var
  FInstance : TArtImageLibraryImageLists;

function ArtImageLibraryImageLists : TArtImageLibraryImageLists;
begin
  If not Assigned( FInstance ) then
    FInstance := TArtImageLibraryImageLists.Create( nil );
  Result := FInstance;
end;


function ArtIconLibraryImageList16 : TImageList;
begin
  Result := ArtImageLibraryImageLists.ImageList16;
end;

function ArtIconLibraryImageList32 : TImageList;
begin
  Result := ArtImageLibraryImageLists.ImageList32;
end;

function ArtIconLibraryImageList48 : TImageList;
begin
  Result := ArtImageLibraryImageLists.ImageList48Shadow;
end;

【问题讨论】:

  • 启动时似乎需要数据模块,但启动时需要 48x48 图像吗?

标签: delphi timagelist tpngimagelist


【解决方案1】:
  1. 您说“一个简单的‘首次使用时创建’方法实例化了这个 TDataModule”,然后又说问题是启动时间。数据模块实际是什么时候创建的?
  2. 您是否分析了应用程序以确保加载图像列表时存在问题?
  3. 如果问题实际上是图像列表,您需要 png 吗?如果它们是这样存储的,则需要对其进行解码并添加到 imagelist 位图中。 ImageList_LoadImage() 可以一步加载位图。

【讨论】:

  • 1 - 是的,它是在第一次分配对图像列表的引用时创建的。 2 - 是的。加载包含我的 3 个图像列表的数据模块的 DFM 资源很慢。 3. PNG - 我正在使用透明度,但这是一个好点,也许我会看看其他格式。谢谢。
猜你喜欢
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
  • 2013-11-13
  • 2019-04-29
  • 2012-05-31
相关资源
最近更新 更多