如何提高Delphi TPngImageList(或TImageList)的加载时间
我在我的应用程序中使用了一组大约 100 个图标,这些图标是使用固定参考编号访问的,并且这些编号也可供用户选择图标。所需的三种分辨率是 16x16、32x32 和 48x48。这些分辨率中的每一个都保存在 TPngImageList 中,并且我使用包含这三个图像列表 (TArtImageLibraryImageLists) 的 TDataModule 创建了一个“图标库”。当需要任何图像列表时,一个简单的“首次使用时创建”方法会实例化此 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;
I'm using a set of around 100 icons in my application, these are accessed using fixed refrence numbers and these numbers are also made available for the user to choose an icon. The three resolutions that are required are 16x16, 32x32 and 48x48. Each of these resolutions are held in a TPngImageList and I've created an 'icon library' using a TDataModule than contains these three image lists (TArtImageLibraryImageLists). A simple 'create on first use' method instantiates this TDataModule when any of its Image Lists are required. The LargeImages or somesuch property of any controls that require access to an image list are simply set by calling the required resolution function.
The problem is the load time when the program starts, which is about 1s on a fast machine. Obviously the worst culprit is the 48x48 image list but I'm wondering if there is a better load mechanism (eg using a resource file?) that will speed up things. Or is there a way I can reformat the image lists? I will still need a TImageList at runtime, e.g for my TreeView's etc.
Thanks,
Brian.
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)