同一下程序可以在 Rgn 中得到一个区域,希望对你有帮助
procedure MaskGenerator(Bitmap:TBitmap;TransparentColor:TColor;var Rgn:HRGN);
var
X,Y:Integer;
Rgn1,Rgn2:HRGN;
StartX,EndX:Integer;
begin
Rgn1:=0;
for Y:=0 to Bitmap.Height-1 do
begin
Application.ProcessMessages;
X:=0;
repeat
while (Bitmap.Canvas.Pixels[X,Y]=TransparentColor) and (X<=Bitmap.Width) do
Inc(X);
StartX:=X;
while (Bitmap.Canvas.Pixels[X,Y]<>TransparentColor) and (X<=Bitmap.Width) do
Inc(X);
EndX:=X;
if StartX<>Bitmap.Width then
begin
if EndX=Bitmap.Width then Dec(EndX);
if Rgn1=0 then
begin
Rgn1:=CreateRectRgn(StartX,Y,EndX,Y+1);
end
else
begin
Rgn2:=CreateRectRgn(StartX,Y,EndX,Y+1);
if Rgn2<>0 then
CombineRgn(Rgn1,Rgn1,Rgn2,RGN_OR);
DeleteObject(Rgn2);
end;
end;
until X>=Bitmap.Width-1;
end;
if Rgn1<>0 then Rgn:=Rgn1;
end;