PNG在德尔福2009图像清单和图像 [英] PNGs in Delphi 2009 Imagelists and Images

查看:157
本文介绍了PNG在德尔福2009图像清单和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

D2009引入了PNG对图像和图像列表的支持。

D2009 introduces PNG support for Images and Imagelists.

但是...

我有一个imagelist包含png图像与alpha。我想使用TImage将其中一个放在表单上。如何做到这一点,让图像很好地合成?

I have an imagelist containing png images with alpha. I want to place one of these on a form using a TImage. How do I do this and get the image nicely composited?

作为一个问题的例子,我面临的代码无法正常工作,并产生显示的效果:

As an example of the problem I'm facing the code below fails to work correctly, and produces the effect shown:

ImageList.GetBitmap(index, Image1.Picture.Bitmap);

alt text http://clip2net.com/clip/m0/1234439882-clip-5kb.png

更多解释:

在表单上删除时间,在设计时,使用Picture属性加载带有alpha的PNG文件。请注意,如何在表单上正确地组合完整的透明度。

Drop a Timage on a form, and at design time, load a PNG file with alpha using the Picture property. Note how it is correctly composited with full transparency onto the form.

现在,在设计时,添加第二个空的Timage,添加一个TImagelist,并将相同的PNG添加到图像列表。如何将TImageList中的PNG分配给第二个TImage,并将其看起来与第一个TImage相同?

Now, at design time, add a second empty Timage, add a TImagelist, and add the same PNG to the imagelist. How can I assign the PNG in the TImageList to the second TImage, and have it look identical to the first one?

推荐答案

从我的研究发现,TImageList将图像作为TBitmaps存储,所以Alpha存储信息丢失,您无法使用TImageList的当前实现来实现您要查找的内容。

From my research I found that TImageList stores the images as TBitmaps, so the alpha information is lost on storage, and you can't achieve what you're looking for with the current implementation of TImageList.

更新:

再多一点实验,并使用下面的代码,我可以透明地使用下面的代码。 p>

A little more experiments and with the code below i could make transparency work with the code below.

ImageList1.ColorDepth := cd32Bit;
Image2.Transparent := True;
Image2.Canvas.Pen.Style := psClear;
Image2.Canvas.Rectangle(0, 0, Image2.Width+1, Image2.Height+1);
ImageList1.Draw(Image2.Canvas, 0,0,0);

但它看起来并不像加载的png那么漂亮。

But it didn't look as pretty as a loaded png.

这篇关于PNG在德尔福2009图像清单和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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