如何清除timage
画布以避免在更改输入尺寸时出现重复图像?为什么nil命令不起作用?
这是我的代码
begin
image1.Canvas := nil;
image1.Canvas.Pen.Color := clRed;
image1.Canvas.Brush.Color := clBlue;
image1.canvas.rectangle(10,10,vwpj,vwlb);
end;
答案 0 :(得分:2)
您无法将Nil
或任何值分配给Canvas
,Canvas
是一个只读的属性,因此您需要删除第一行,然后在TImage
画布:
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Brush.Color := clBlue;
Image1.canvas.rectangle(0,0,Image1.Height,Image1.Width);
编辑: 每次在画布上绘制时,都必须将图像设置为默认值:
步骤:
Procedure TForm1.Default(Image: TImage);
begin
Image.Canvas.Pen.Color := clBtnFace;
Image.Canvas.Brush.Color := clBtnFace;
Image.Canvas.FillRect(Rect(0,0,Image.Height,Image.Width));
end;
然后将其称为:
procedure TForm1.Button1Click(Sender: TObject);
begin
Default(Image1);
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Brush.Color := clBlue;
Image1.canvas.rectangle(0,0,Image1.Height,Image1.Width);
end;
答案 1 :(得分:-1)
根据您所写的内容,并尝试在之前的许多编辑中进行解释。 这可以解决您的问题。
<强>要求:强>
TEdit
组件。TButton
。TImage
。<强>代码:强>
var
Xorigin,Yorigin,vwpj,vwlb:integer;
....
begin
vwpj := strtoint(vwpjEdit.text);
vwlb := strtoint(vwlbEdit.text);
Xorigin := strtoint(XoriginEdit.Text);
Yorigin := strtoint(YoriginEdit.Text);
// You have to wipe the canvas with a base color,
image1.Canvas.Brush.Color := clwhite;
image1.Canvas.FillRect(rect(0,0,image1.Width,image1.height));
image1.Canvas.Pen.Color := clRed;
image1.Canvas.Brush.Color := clBlue;
image1.Canvas.rectangle(Xorigin,Yorigin,vwlb,vwpj);
end;
说明:我知道您想在Canvas
的{{1}}属性上绘制一个矩形。根据每次调整矩形大小的条件,您要清除TImage
(由于Canvas
是只读属性,因此将nil
分配给画布是错误的。
现在上面的代码是通过使用Canvas
方法用基色(我选择clwhite
)填充画布来实现的。
从这里你需要了解没有清除图像这样的东西,要么你删除它(使用你所说的Fillrect()
命令)它会消失,如果你想在它上画画再次,你需要创建它。
第二个选项是用背景颜色(我选择的基础free
)填充它,或者作为第三个选项,也可以调整图像大小。
所有重要的是,只要该图像仍在那里,画布和您在其上绘制的内容将保留。
上述代码的结果