图片用bmp的,背景色要唯一,比如说黑色。
窗体bsnone,AutoSize:=True;
BackColor:TColor;
BackColor:=Image1.Canvas.Pixels[2,2];//假设这里是要过滤的背景色
procedure TForm1.FormShow(Sender: TObject);
var
MyRgn, ClientRgn, ButtonRgn,bmpRgn: THandle;
Margin, X, Y: Integer;
p : Tpoint;
begin
Margin := (Width - ClientWidth) div 2;
MyRgn := CreateRectRgn(0, 0, Width, Height);
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);
CombineRgn(MyRgn, MyRgn, ClientRgn, RGN_XOR);
//X := X + Button1.Left;
// Y := Y + Button1.Top;
// ButtonRgn := CreateRectRgn(X, Y, X + Button1.Width, Y + Button1.Height);
//-----------!!-----------
//有别的控件可以在这里插入。
// CombineRgn(MyRgn, MyRgn, ButtonRgn, RGN_XOR);
//Image1.Picture.LoadFromFile('c:/ts1.bmp');
for x:=0 to Image1.width-1do
for y:=0 to Image1.height-1do
begin
if Image1.Canvas.Pixels[x,y]<> BackColor then
begin
bmpRgn:= CreateRectRgn(x,y,x+1,y+1);
CombineRgn(MyRgn,MyRgn,bmpRgn,RGN_XOR);
end;
end;
SetWindowRgn(Handle, MyRgn, True);
end;