TDXImageList.Items 中的每個 TPictureCollectionItem 的默認透明色是黑色, 並默認透明.
本例使用的測試圖片: http://files.cnblogs.com/del/Transparent.rar
本例效果圖:
代碼文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DXDraws, StdCtrls, DXClass;
type
TForm1 = class(TForm)
DXDraw1: TDXDraw;
DXImageList1: TDXImageList;
CheckBox1: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
PicItem: TPictureCollectionItem;
procedure TForm1.FormCreate(Sender: TObject);
const
ImgPath1 = 'C:TempTransparent.bmp';
begin
DXImageList1.DXDraw := DXDraw1;
PicItem := TPictureCollectionItem(DXImageList1.Items.Add);
PicItem.Picture.LoadFromFile(ImgPath1);
PicItem.TransparentColor := $FFFFFF; {指定透明色; 我測試用的圖片是白色背景的}
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
const
arr: array[Boolean] of string = ('不透明', '透明');
begin
DXDraw1.Surface.Fill($FF0000);
PicItem.Restore;
PicItem.Transparent := CheckBox1.Checked;
PicItem.Draw(DXDraw1.Surface, 10, 10, 0);
DXDraw1.Flip;
CheckBox1.Caption := arr[CheckBox1.Checked];
end;
end.