image1放到panel1上function GraphicToRGN(mGraphic: TGraphic; mTransPoint: TPoint): HRGN; var I, J: Integer; vStart: Integer; vHandle: HRGN; vTransColor: TColor; begin Result := 0; if not Assigned(mGraphic) then Exit; Result := CreateRectRgn(0, 0, 0, 0); with TBitmap.Create do try Width := mGraphic.Width; Height := mGraphic.Height; Canvas.Draw(0, 0, mGraphic); vTransColor := Canvas.Pixels[mTransPoint.X, mTransPoint.Y]; for I := 0 to Height - 1 do begin vStart := 0; for J := 0 to Width do begin if (Canvas.Pixels[J, I] <> vTransColor) and (J < Width) then if vStart < 0 then vStart := J else else if vStart >= 0 then begin vHandle := CreateRectRgn(vStart, I, J, I + 1); try CombineRgn(Result, Result, vHandle, RGN_OR); finally DeleteObject(vHandle); end; vStart := -1; end; end; end; finally Free; end; end; { GraphicToRGN }procedure TForm1.FormCreate(Sender: TObject); var vRGN: HRGN; begin Image1.Left := 0; Image1.Top := 0; vRGN := GraphicToRGN(Image1.Picture.Graphic, Point(0, 0)); try SetWindowRgn(panel1.Handle, vRGN, True); finally DeleteObject(vRGN); end; end;
var
I, J: Integer;
vStart: Integer;
vHandle: HRGN;
vTransColor: TColor;
begin
Result := 0;
if not Assigned(mGraphic) then Exit;
Result := CreateRectRgn(0, 0, 0, 0);
with TBitmap.Create do try
Width := mGraphic.Width;
Height := mGraphic.Height;
Canvas.Draw(0, 0, mGraphic);
vTransColor := Canvas.Pixels[mTransPoint.X, mTransPoint.Y];
for I := 0 to Height - 1 do begin
vStart := 0;
for J := 0 to Width do begin
if (Canvas.Pixels[J, I] <> vTransColor) and (J < Width) then
if vStart < 0 then
vStart := J
else
else if vStart >= 0 then begin
vHandle := CreateRectRgn(vStart, I, J, I + 1);
try
CombineRgn(Result, Result, vHandle, RGN_OR);
finally
DeleteObject(vHandle);
end;
vStart := -1;
end;
end;
end;
finally
Free;
end;
end; { GraphicToRGN }procedure TForm1.FormCreate(Sender: TObject);
var
vRGN: HRGN;
begin
Image1.Left := 0;
Image1.Top := 0;
vRGN := GraphicToRGN(Image1.Picture.Graphic, Point(0, 0));
try
SetWindowRgn(panel1.Handle, vRGN, True);
finally
DeleteObject(vRGN);
end;
end;
var
vRGN: HRGN;
begin
Image1.Left := 0;
Image1.Top := 0;
vRGN := GraphicToRGN(Image1.Picture.Graphic, Point(10, 10)); ///改改参照点位置~~~
try
SetWindowRgn(panel1.Handle, vRGN, True);
finally
DeleteObject(vRGN);
end;
end;或者直接在GraphicToRGN函数中把vTransColor设成你要的颜色
到www.delphibox.com,www.playicq.com 去找源码,有下的。