使用 Delphi XE 在运行时将 png 图像添加到图像列表 [英] Add a png image to a imagelist in runtime using Delphi XE

查看:18
本文介绍了使用 Delphi XE 在运行时将 png 图像添加到图像列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行时将 png 图像添加到 TImageList.我查看了由 TCustomImageList 实现的功能,但它们只允许添加

I need add in runtime a png image to a TImageList. I've looked at the functions implemented by the TCustomImageList but they only allow adding

  • 位图,
  • 图标或
  • 来自另一个图像列表的图像

例如:

function Add(Image, Mask: TBitmap): Integer;
function AddIcon(Image: TIcon): Integer;
function AddImage(Value: TCustomImageList; Index: Integer): Integer;
procedure AddImages(Value: TCustomImageList);
function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;

如何将 PNG 图像添加到 ImageList 组件而不将该图像转换为 BMP?

How I can add a PNG image to a ImageList component without converting this image to BMP?

IDE 已经可以在设计时将 PNG 添加到 ImageList:

The IDE already can add a PNG to an ImageList at design time:

现在我们需要在运行时进行.

Now we need to do it at runtime.

推荐答案

根据 MSDN,图像列表只能包含位图和图标.要将 png 图像添加到图像列表,您必须先将其转换为图标.可以在 PngComponents 包中找到执行此操作的代码.如果您的图像列表中只有 PNG 图像,为简单起见,您可以使用该包附带的 TPngImageList.

According to MSDN an imagelist can only contain bitmaps and icons. To add a png image to an imagelist you have to convert it to an icon first. The code to do that can be found in the PngComponents package. If you have only PNG images in your imagelist you can for simplicity just use TPngImageList that comes with that package.

这篇关于使用 Delphi XE 在运行时将 png 图像添加到图像列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆