TDXImageList.Items 中的每个 TPictureCollectionItem 的默认透明色是黑色, 并默认透明.
本例使用的测试图片:
本例效果图:
代码文件:
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:\Temp\Transparent.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.