function CreateRgnFromBmp(B: TBitmap; var RgnData: PRgnData): integer;
const
max = 10000;
var
j, i, i1: integer;
C: TFBColor;
FB: TFBitmap;
Rts: array [0..max] of TRect;
Count: integer;
begin
Result := 0;
If B.Empty Then Exit;
Count := 0;
FB := TFBitmap.Create(B.Handle);
for j := 0 to B.Height-1 do
begin
i := 0;
while i < B.Width do
begin
C := FB.Pixels[j, i];
If C.R + C.G + C.B = 0 Then
begin
i1 := i;
C := FB.Pixels[j, i1];
while C.R + C.G + C.B = 0 do
begin
{ Inc(i1);
C := FB.Pixels[j, i1];
If i1 >= B.Width Then Break;} // modify kang
Inc(i1);
If i1 >= B.Width Then Break;
C := FB.Pixels[j, i1];
end;
Rts[Count] := Rect(i, j, i1, j+1);
Inc(Count);
i := i1;
Continue;
end;
Inc(i);
end;
end;
FB.Free;
// Make Region data
Result := Count*SizeOf(TRect);
GetMem(Rgndata, SizeOf(TRgnDataHeader)+Result);
FillChar(Rgndata^, SizeOf(TRgnDataHeader)+Result, 0);
RgnData^.rdh.dwSize := SizeOf(TRgnDataHeader);
RgnData^.rdh.iType := RDH_RECTANGLES;
RgnData^.rdh.nCount := Count;
RgnData^.rdh.nRgnSize := 0;
RgnData^.rdh.rcBound := Rect(0, 0, B.Width, B.Height);
// Update New Region
Move(Rts, RgnData^.Buffer, Result);
Result := SizeOf(TRgnDataHeader)+Count*SizeOf(TRect);
end;
这是epForm的Source,此函数根据一个图形求出边界.
可能有帮助.