以 png 格式剪辑幻灯片 (Delphi 2010)
我有一个 png 格式的图像幻灯片,如下所示:
我想知道如何剪辑每个图像并将这些图像放入 TImageList 控件中,始终保留透明度。
[编辑]
是的,在设计时,RRUZ 提到的技巧工作得很好,但我想在运行时剪辑图像,即通过从资源或文件加载幻灯片
I have a filmstrip of images in png format like this:
I'd like to know how to clip each of the images and put these images in a TImageList control, always preserving the transparency.
[EDIT]
Yes, at designtime the trick mentioned by RRUZ works fine, but I wanted to clip the images at runtime, i.e. by loading the filmstrip from resource or file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须按照以下步骤操作:
将
ColorDepth
属性设置为cd32Bit
,DrawingStyle
到dsTransparent
,高度
= 48,宽度
=48,然后加载图像,结果将是
You must follow these steps:
set
ColorDepth
property tocd32Bit
,DrawingStyle
todsTransparent
,Height
= 48,Width
=48,then load the image and the result will be
只需导入到图像列表中即可。它会抱怨它太大,并主动提出为你把它分成碎片。我在 D2005 上工作得很好。
另一个很酷的提示:我使用 AWIcons Pro http://www.awicons.com/icon-editor/ 编辑图标(不错的编辑器!)。它具有可以将图标导出为图像列表(.bmp 或.png 格式)的功能,从而使幻灯片不再是图标。这使得以 .ico 格式编辑这些内容变得非常方便,一系列单元格的大小和深度都相同,每个单元格略有不同。然后导出为图像列表(我使用 .png),然后 Delphi 可以将它们分解回单独的单元格。非常光滑。 AWIcons 不是免费的,但这样的功能确实让它变得高效。
Just import into the imagelist. It'll complain that it's too big and offer to break it into pieces for you. Works fine for me on D2005.
Another cool tip: I use AWIcons Pro http://www.awicons.com/icon-editor/ to edit icons (nice editor!). It has a feature that can export an icon as an imagelist (.bmp or .png format), thus making the filmstrip out of an icon. This makes it really handy to edit these things in .ico format, with a series of cells all the same size and depth, with each cell varying slightly. Then you export as an imagelist (I use .png) and then Delphi can break them back out into individual cells. Very slick. AWIcons isn't free, but features like this really make it productive.
在运行时,您必须调用 TImageList.FileLoad。除非它不起作用。
这又调用 ImageList_LoadImage,uFlags 参数值包括位 LR_LOADFROMFILE,这会导致 Windows 从磁盘上的文件加载。此底层功能仅支持 TBitmap (BMP) 格式。
请参阅几乎重复的问题。 PNG 支持是一项设计时功能,可将 PNG 数据转换为内部非 PNG 格式且不完全是 BMP 格式,由 MS 通用控件库内部使用。以文本形式查看您的 DFM,您将看到您的 PNG 输入已变成什么。其他答案表明,使用基于位图颜色的透明度保留了透明度。
如果您想以 PNG 格式保存数据,则不应使用 VCL TImageList 来存储它,因为您必须将 PNG 转换为 TBitmap 才能实际使用 TImageList。
At runtime, you would have to call TImageList.FileLoad. Except it won't work.
This in turn calls ImageList_LoadImage, with uFlags parameter value including the bit LR_LOADFROMFILE, which causes Windows to load from a file on disk. This underlying functionality only supports TBitmap (BMP) format.
See the nearly-duplicate question. PNG support is a designtime feature that is converting the PNG data into an internal non-PNG and not-exactly-a-BMP-either format, used internally by MS Common Controls library. View your DFM as text, and you will see what your PNG inputs have been turned into. The other answers show you that transparency is preserved, using bitmap-color based transparency.
If you want to keep your data in PNG format, you shouldn't be using a VCL TImageList to store it, because you're going to have to do a conversion from PNG to TBitmap to actually use TImageList.