如何填充一个封闭的区域 在一个图形面板上,有许多的矩形框、线条及园,点击鼠标后,如何填充其周围的一块封闭区域 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 几何好就很简单,先算出闭合区域的大小,然后用FillRect来填充 先得出Rect 的大小,在用FillRect填充。 现在就是计算RECT的问题,写了一个算法,但出现堆栈溢出,代码如下:procedure FillPoly(Canvas :TCanvas;Po :TPoint;FillColor :TColor;OldFillColor :TColor);type TFillDirection = (fdLeft,fdTop,fdRight,fdBottom); procedure Fill(Po :TPoint;FillDirection :TFillDirection); begin if Canvas.Pixels[Po.X,Po.Y] <> OldFillColor then Exit; case FillDirection of fdLeft :begin if Po.X <=0 then Exit; if Canvas.Pixels[Po.X - 1,Po.Y] = OldFillColor then Fill(Point(Po.X - 1,Po.Y),fdLeft); if Canvas.Pixels[Po.X,Po.Y - 1] = OldFillColor then Fill(Point(Po.X ,Po.Y - 1),fdTop) end; fdTop :begin if Po.Y <= 0 then Exit; if Canvas.Pixels[Po.X + 1,Po.Y] = OldFillColor then Fill(Point(Po.X + 1,Po.Y),fdRight); if Canvas.Pixels[Po.X ,Po.Y - 1] = OldFillColor then Fill(Point(Po.X,Po.Y - 1),fdTop) end; fdRight :begin if Canvas.Pixels[Po.X + 1,Po.Y] = OldFillColor then Fill(Point(Po.X + 1,Po.Y),fdRight); if Canvas.Pixels[Po.X,Po.Y + 1] = OldFillColor then Fill(Point(Po.X,Po.Y + 1),fdBottom) end; fdBottom:begin if Canvas.Pixels[Po.X - 1,Po.Y] = OldFillColor then Fill(Point(Po.X - 1,Po.Y),fdLeft); if Canvas.Pixels[Po.X,Po.Y + 1] = OldFillColor then Fill(Point(Po.X,Po.Y + 1),fdBottom) end; end; Canvas.Pixels[Po.X,Po.Y] := FillColor; end;begin Fill(Point(Po.X - 1,Po.Y - 1),fdLeft); Fill(Point(Po.X + 1,Po.Y + 1),fdRight); Fill(Point(Po.X - 1,Po.Y + 1),fdBottom); Fill(Point(Po.X + 1,Po.Y - 1),fdTop);end; 如果不是矩形区域,使用 FillRgn 关于两个等长字符串异或求助 为什么会出现socket Error #10054 Connection resetby peer错误提示 ole应用 请问怎么设置图片(位图或其它)的分辨率? 怎样将txt中内容全部读入memo中? DELPHI如何调用中兴无线宽带上网卡(USB)的驱动程序做拨号和断开? 问一个弱弱的有关webbrowse读取xml的问题,在线等!!! 关于ListView的OnSelectitem方法? 调查:技术资料 关于DELPHI导出到EXCEL的问题请教 释放和指针的问题,好难懂 急!!高分求助!
type
TFillDirection = (fdLeft,fdTop,fdRight,fdBottom); procedure Fill(Po :TPoint;FillDirection :TFillDirection);
begin
if Canvas.Pixels[Po.X,Po.Y] <> OldFillColor then Exit;
case FillDirection of
fdLeft :begin
if Po.X <=0 then Exit;
if Canvas.Pixels[Po.X - 1,Po.Y] = OldFillColor then
Fill(Point(Po.X - 1,Po.Y),fdLeft);
if Canvas.Pixels[Po.X,Po.Y - 1] = OldFillColor then
Fill(Point(Po.X ,Po.Y - 1),fdTop)
end;
fdTop :begin
if Po.Y <= 0 then Exit;
if Canvas.Pixels[Po.X + 1,Po.Y] = OldFillColor then
Fill(Point(Po.X + 1,Po.Y),fdRight);
if Canvas.Pixels[Po.X ,Po.Y - 1] = OldFillColor then
Fill(Point(Po.X,Po.Y - 1),fdTop)
end;
fdRight :begin
if Canvas.Pixels[Po.X + 1,Po.Y] = OldFillColor then
Fill(Point(Po.X + 1,Po.Y),fdRight);
if Canvas.Pixels[Po.X,Po.Y + 1] = OldFillColor then
Fill(Point(Po.X,Po.Y + 1),fdBottom)
end;
fdBottom:begin
if Canvas.Pixels[Po.X - 1,Po.Y] = OldFillColor then
Fill(Point(Po.X - 1,Po.Y),fdLeft);
if Canvas.Pixels[Po.X,Po.Y + 1] = OldFillColor then
Fill(Point(Po.X,Po.Y + 1),fdBottom)
end;
end;
Canvas.Pixels[Po.X,Po.Y] := FillColor;
end;
begin
Fill(Point(Po.X - 1,Po.Y - 1),fdLeft);
Fill(Point(Po.X + 1,Po.Y + 1),fdRight);
Fill(Point(Po.X - 1,Po.Y + 1),fdBottom);
Fill(Point(Po.X + 1,Po.Y - 1),fdTop);
end;
使用 FillRgn