本例效果图:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;procedure FormCreate(Sender: TObject);procedure FormPaint(Sender: TObject);procedure Button1Click(Sender: TObject);procedure FormDblClick(Sender: TObject);procedure FormDestroy(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}varbit: TBitmap;procedure TForm1.FormCreate(Sender: TObject);
beginbit := TBitmap.Create;bit.LoadFromFile('c: emp est.bmp');
end;procedure TForm1.FormPaint(Sender: TObject);
beginCanvas.Draw(0, 0, bit);
end;procedure TForm1.Button1Click(Sender: TObject);
varrgn1,rgn2: HRGN;x,y,w,h: Integer;
beginw := bit.Width;h := bit.Height;rgn1 := CreateRectRgn(0, 0, w, h);for x := 0 to w - 1 dofor y := 0 to h - 1 doif bit.Canvas.Pixels[x,y] = clBlack thenbeginrgn2 := CreateRectRgn(x, y, x+1, y+1);CombineRgn(rgn1, rgn1, rgn2, RGN_XOR);DeleteObject(rgn2);end;SetWindowRgn(Handle, rgn1, True);Self.BorderStyle := bsNone;Self.Width := w;Self.Height := h;
end;procedure TForm1.FormDblClick(Sender: TObject);
beginClose;
end;procedure TForm1.FormDestroy(Sender: TObject);
beginbit.Free;
end;end.