我基于TGraphic控件创建了一个组件。
当我直接在画布上画线时,它是透明的。但当我试图在画布上绘制位图时,它不会显示为透明。
如何在画布上绘制透明位图?
谢谢
unit Test;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,Types,DB;
type
TTest = class(TgraphicControl)
private
{ Private declarations }
BMP:TBitmap;
protected
{ Protected declarations }
Procedure Paint; Override;
public
{ Public declarations }
Constructor create(Aoner: Tcomponent); Override;
Destructor Destroy; Override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Automation', [TTest]);
end;
Constructor TTest.create(Aoner: TComponent);
begin
Inherited Create(Aoner);
Width:=100;
Height:=100;
Bmp := TBitmap.Create;
BMp.Width:=50;
BMP.Height:=50;
BMP.Transparent:=true;
BMP.TransparentColor:=BMp.Canvas.Pixels[0,0];
BMP.Canvas.MoveTo(1,1);
BMP.Canvas.LineTo(50,50);
End;
Procedure TTest.Paint;
Begin
Inherited Paint;
Canvas.MoveTo(0,0);
Canvas.LineTo(100,100);
Canvas.Draw(0,0,BMp);
End;
Destructor TTest.Destroy;
begin
Inherited Destroy;
end;