Delphi 与 DirectX 之 DelphiX(9): 透明色与是否透明


TDXImageList.Items 中的每个 TPictureCollectionItem 的默认透明色是黑色, 并默认透明.

本例使用的测试图片: http://files.cnblogs.com/del/Transparent.rar

本例效果图:

Delphi 与 DirectX 之 DelphiX(9): 透明色与是否透明

代码文件:

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.


 
   

你可能感兴趣的:(Delphi)