【问题标题】:Delphi PNG images collection in a component组件中的 Delphi PNG 图像集合
【发布时间】:2016-06-30 16:16:37
【问题描述】:

今天我的问题是关于在组件中创建 PNG 图像的集合。 我找到了一个接受 PNG 图像作为 gliph 的按钮,但它使用由图像的四种状态组成的 PNG 图像,如下所示:

我已经修改了组件以使用四个不同的图像,每个图像用于一个状态。所以,我的组件看起来像这样:

  ...
  public
    FPngImgEnabled: TPngImage;
    FPngImgDisabled: TPngImage;
    FPngImgDown: TPngImage;
    FPngImgOver: TPngImage;
    FDown: Boolean;
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
    procedure Paint; override;
  published
    property PngImgEnabled: TPngImage read FPngImgEnabled write SetPngImgEnabled;
    property PngImgDisabled: TPngImage read FPngImgDisabled write SetPngImgDisabled;
    property PngImgDown: TPngImage read FPngImgDown write SetPngImgDown;
    property PngImgOver: TPngImage read FPngImgOver write SetPngImgOver;
  ...

这样我就有了一个包含四个PNG图像的组件,然后是SetPng...程序。我想知道是否有办法使用四个PNG图像的集合;像“TPNGImagesList”这样的东西,用于将图像集中在一个地方。

【问题讨论】:

  • TImageList 有什么问题?
  • PngComponents 中包含 TPngImageList。也许这符合您的需求。也许甚至包括一个现成的按钮 - 我还没有检查过。
  • 附:TPNGImageList也有什么问题?顺便说一句,哪个 Delphi 版本?
  • Delphi 的哪个版本?如果您可以访问泛型,为什么不使用它呢?创建类型TImageState = (isEnabled, isDisabled, isDown, isOver);,然后使用TObjectDictionary<TImageState, TPngImage>。字典可以拥有图像对象并自行释放它们。
  • 我使用的Delphi版本是XE7

标签: delphi png delphi-xe7


【解决方案1】:

我认为你需要这样的东西:

  type
    TImgType = (itEnabled, itDisabled, itDown, itOver);


  ...
  protected
    procedure SetImg(Index: TImgType; Value: TPngImage);
    function  GetImg(Index: TImgType): TPngImage;      
  public
    FImages: TList<TPngImage>;
    FDown: Boolean;
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
    procedure Paint; override;
  published
    property Image[Index:TImgType]: TPngImage read GetImg write SetImg;
    property PngImgEnabled: TPngImage index itEnabled read GetImg write SetImg;
    property PngImgDisabled: TPngImage index itDisabled read GetImg write SetImg;
    property PngImgDown: TPngImage index itDown read GetImg write SetImg;
    property PngImgOver: TPngImage index itOver read GetImg write SetImg;

  ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    • 2010-09-15
    • 2016-11-25
    • 2020-08-08
    • 2019-07-05
    • 2021-08-17
    • 2019-03-12
    相关资源
    最近更新 更多