TMainMenu 中的透明 PNG 图像(带有 TImageList)

发布于 2024-11-29 23:16:18 字数 392 浏览 4 评论 0原文

我想在 TImageList 中加载具有透明背景的 PNG 并在 TMainMenu 中使用它(通过 TAction)。
然而,在 Delphi 中,背景只是黑色。

这个家伙说这对他有用,但用的是按钮而不是主菜单。

我的设置:

  • 我的图像是每种颜色 8 位加上 8 位透明通道(我也尝试过使用 1 位透明度,但仍然不起作用)。该图像在任何其他程序中看起来都很好。
  • 德尔福XE。
  • 在 TImageList 的编辑器中,“透明颜色”和“填充颜色”设置为“默认”并被禁用。

I want to load a PNG with transparent background in a TImageList and use it in a TMainMenu (via TAction).
However, in Delphi the background is just black.

This guy says it worked for him, but with a button instead of a main menu.

My setup:

  • My image is 8 bit per color plus 8 bit for transparency channel (I have tried also with 1 bit for transparency but still doesn't work). The image looks just fine in any other program.
  • Delphi XE.
  • In TImageList's editor, the 'transparent color' and 'Fill color' are set to 'Default' and are disabled.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

作业与我同在 2024-12-06 23:16:18

没有理由备份整个 DFM 文件。

在对 ImageList 进行操作之前,您应该导出图像:单击图像列表编辑器中的“导出”按钮,它会将所有图像保存到单个 .BMP 文件中。

更改属性后: ColorDepth = cd32Bit, DrawingStyle = dsTransparent

您应该单击“添加”按钮并选择之前导出的文件。然后,图像将在菜单和工具栏中以透明方式绘制(至少在 D2010 上)...无需使用第 3 方组件。

There's no reason to backup whole DFM file.

Before doing something to your ImageList you should export your images: click the "Export" button in the image list editor and it will save all images to a single .BMP file.

After changing properties: ColorDepth = cd32Bit, DrawingStyle = dsTransparent

You should click "Add" button and select the file you previously exported. Then, images will be drawn with transparency in the menu and toolbars (on D2010 at least)... No need to use 3rd party components.

躲猫猫 2024-12-06 23:16:18
  1. 为TImageList设置以下属性值:
  • DrawingStyle: dsTransparent
  • ColorDepth: cd32Bit
  • TImageList的编辑器->将“透明颜色”设置为 True
  1. 在“应用程序”下的“项目设置”中设置“启用运行时主题”。

Delphi Rio 更新:

TImageList 必须具有:

  • BkGColor = clNone
  • BlendColor = clNone、
  • ColorDepth = cd32bit、
  • DrawingStyle = dsTransparent(或)dsNormal、
  • Masked = true。

图像可以从具有透明 bkg 颜色的 PNG 加载。


注意:编辑 TImageList 的某些属性将删除(恕不另行通知)列表中的所有现有图像。首先备份您的图像(或 DFM)。

  1. Set the following property values for TImageList:
  • DrawingStyle: dsTransparent
  • ColorDepth: cd32Bit
  • TImageList's editor -> set the 'transparent color' to True
  1. In "Project Settings" under "Application" set "Enable runtime themes".

Update for Delphi Rio:

TImageList must have:

  • BkGColor = clNone
  • BlendColor = clNone,
  • ColorDepth = cd32bit,
  • DrawingStyle = dsTransparent (or) dsNormal,
  • Masked = true.

The images can be loaded from a PNG with transparent bkg color.


Note: Editing some properties of TImageList will delete (without any notice) all existing images in your list. Backup your images (or DFM) first.

清浅ˋ旧时光 2024-12-06 23:16:18

自 Delphi 7 以来,我一直在使用 TPngComponents。它为大多数 delphi 内置/第三方提供了非常好的 png 支持成分。 Embarcadero 购买了另一个众所周知的开源 PNG 支持组件,称为 TPngImage,并在以后的 Delphi 版本中构建到 Delphi 的本机图形支持中。所以当我换到Delphi 2010时,我认为Delphi现在有了原生支持并测试了原生支持,但发现alpha支持不够好。

所以我再次使用了 TPngComponents,它对大多数组件都有更好的支持,包括主菜单。我认为该包应该可以在 DXE 中使用,只需进行有限的修改。

编辑:感谢 Uwe Raabe 指出 Codegear(现在的 Embarcadero)购买的产品是另一个组件 TPngImage 而不是 TPngComponent。

I had been using TPngComponents since Delphi 7. That provide very good png support for most of the delphi build-in / third party components. Embarcadero had purchased another well know Open Sources PNG Supporting component know as TPngImage and build into Delphi's native graphic support in later Delphi versions. So when I changed to Delphi 2010, I think Delphi had native support now and test out the native support but find that the alpha support is not good enough.

So I had used back that TPngComponents again and it had better support for most components, including main menu. I think that package should be usable to DXE with limited modification.

edit : Thanks for Uwe Raabe for pointing out the product Codegear (now Embarcadero) purchased was another component TPngImage rather then the TPngComponent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文