【发布时间】:2014-05-21 18:12:38
【问题描述】:
我有如下图
我想让图像变得像
我已经编写了代码,如下所示:
var
Tx,Ty, R,G,B,A, posX, posY : integer;
begin
posX :=-1; posY := -1;
for Ty:= 0 to Image1.Height-1 do
begin
for Tx:= 0 to Image1.Width-1 do
begin
R:= GetRValue(image1.Canvas.Pixels[Tx, Ty]);
G:= GetGValue(image1.Canvas.Pixels[Tx, Ty]);
B:= GetBValue(image1.Canvas.Pixels[Tx, Ty]);
A:= (R + G + B) Div 3;
if (A > 50) then
begin
Image1.Canvas.Pixels[Tx,Ty] := rgb(255,255,255);
end else
begin
Image1.Canvas.Pixels[Tx,Ty] := rgb(0,0,0);
if (posX < 0) then
begin
posX := Tx;
posY := Ty;
end;
end;
end;
end;
Image1.Canvas.Brush.Style := bsSolid;
Image1.Canvas.Brush.Color := clred;
Image1.Canvas.FloodFill(posX,posY,clBlack,fsSurface);
end;
我上面的编码只能使填充仅用于点。
我怎样才能使填充像结果图像一样?谢谢
【问题讨论】:
-
您可以使用
FillRgn填充区域,但您将如何定义该区域?我的直觉告诉我,你试图以错误的方式解决问题。我们可以通过这种方式帮助您解决问题,但在我看来,帮助您找到更好的解决方案会更有意义。 -
您似乎误解了“flood-fill”的含义。当您在图像编辑程序中使用等效工具(如 MS Paint)时,您不会得到相同的结果吗?您的代码将浅色像素变为白色,将深色像素变为黑色,然后您想将黑色像素更改为红色。为什么要先把它们弄黑?直接把它们改成红色就行了。
标签: delphi flood-fill