如何在Delphi TImageList 中使用 透明 png 图标

前一段时间写一个程序,ImageList中添加PNG图片,Toolbar引用ImageList中的PNG图片时,图片背景是黑色,

其实只要设置ImageList的一个属性:ColorDepth设置成cd32Bit就可以了。

 

2010-11-29 17:06

[转] 如何在Delphi TImageList 中使用 透明 png 图标

原文标题:How to use transparent PNG icons with Delphi ImageList

原文:http://www.aha-soft.com/faq/delphi-imagelist-png.htm

Query: "Embarcadero Delphi ImageList does not show transparent PNG icons correctly. How to fix it?".

Solution: If you want to use 32-bit (24-bit + alpha channel) PNG icons within Delphi TImageList, you need to set the following property values for TImageList.DrawingStyle: dsTransparent
ColorDepth: cd32Bit

 

[英雄区] ServerName=冲浪传奇(英雄电信) ServerIP=115.238.246.100 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [英雄区] ServerName=冲浪传奇(英雄网通) ServerIP=103.246.155.100 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [英雄区] ServerName=飓风时代(英雄电信) ServerIP=115.238.246.100 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [英雄区] ServerName=飓风时代(英雄网通) ServerIP=103.246.155.100 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧一区(电信) ServerIP=115.238.250.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧一区(网通) ServerIP=60.12.121.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧二区(电信) ServerIP=115.238.250.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧二区(网通) ServerIP=60.12.121.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧三区(电信) ServerIP=115.238.250.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧三区(网通) ServerIP=60.12.121.44 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧四区(电信) ServerIP=115.238.251.110 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧四区(网通) ServerIP=60.12.121.110 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com DownUrl=http://www.mircl.com [怀旧区] ServerName=经典怀旧五区(电信) ServerIP=115.238.251.110 ServerPort=8000 ServerWeb=http://www.mircl.com BuyUrl=http://www.mircl.com Do
procedure BitmapFileToPNG(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin Bitmap := TBitmap.Create; PNG := TPNGObject.Create; {In case something goes wrong, free booth Bitmap and PNG} try Bitmap.LoadFromFile(Source); PNG.Assign(Bitmap); //Convert data into png PNG.SaveToFile(Dest); finally Bitmap.Free; PNG.Free; end end; Converting from PNG file to Windows bitmap file The above inverse. Loads a png and saves into a bitmap procedure PNGFileToBitmap(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin PNG := TPNGObject.Create; Bitmap := TBitmap.Create; {In case something goes wrong, free booth PNG and Bitmap} try PNG.LoadFromFile(Source); Bitmap.Assign(PNG); //Convert data into bitmap Bitmap.SaveToFile(Dest); finally PNG.Free; Bitmap.Free; end end; Converting from TImage to PNG file This method converts from TImage to PNG. It has full exception handling and allows converting from file formats other than TBitmap (since they allow assigning to a TBitmap) procedure TImageToPNG(Source: TImage; const Dest: String); var PNG: TPNGObject; BMP: TBitmap; begin PNG := TPNGObject.Create; {In case something goes wrong, free PNG} try //If the TImage contains a TBitmap, just assign from it if Source.Picture.Graphic is TBitmap then PNG.Assign(TBitmap(Source.Picture.Graphic)) //Convert bitmap data into png else begin //Otherwise try to assign first to a TBimap BMP := TBitmap.Create; try BMP.Assign(Source.Picture.Graphic); PNG.Assign(BMP); finally BMP.Free; end; end; //Save to PNG format PNG.SaveToFile(Dest); finally PNG.Free; end end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值