我想使用 TPathData 创建类似网格的表单,然后使用 DrawPath 打印到画布,但我不想使用 DrawRect 等直接打印到画布。这是我的问题的一个简化示例,使用两个叠加的矩形形成一个加号。问题是这样的:在画布上渲染时,十字的中间是白色的:
这是我用来创建此图像的方法:
procedure TForm3.Button1Click(Sender: TObject);
var PD: TPathData;
aRect1, aRect2: TRectF;
begin
aRect1 := RectF(45,10,55,90);
aRect2 := RectF(10,45,90,55);
PD := TPathData.Create;
begin
PD.MoveTo(aRect1.TopLeft);
PD.LineTo(PointF(aRect1.Right,aRect1.Top));
PD.LineTo(PointF(aRect1.Right,aRect1.Bottom));
PD.LineTo(PointF(aRect1.Left,aRect1.Bottom));
PD.LineTo(aRect1.TopLeft);
end;
begin
PD.MoveTo(aRect2.TopLeft);
PD.LineTo(PointF(aRect2.Right,aRect2.Top));
PD.LineTo(PointF(aRect2.Right,aRect2.Bottom));
PD.LineTo(PointF(aRect2.Left,aRect2.Bottom));
PD.LineTo(aRect2.TopLeft);
end;
ImageControl1.Bitmap.SetSize(Round(ImageControl1.BoundsRect.Width), Round(ImageControl1.BoundsRect.Height));
if ImageControl1.Bitmap.Canvas.BeginScene then
try
with ImageControl1.Bitmap.Canvas do
begin
clear(0);
Fill.Kind := TBrushKind.Solid;
Fill.Color := TAlphaColorRec.Black;
Stroke.Thickness := 1;
DrawPath(PD,1);
FillPath(PD,1);
end;
finally
ImageControl1.Bitmap.Canvas.EndScene;
FreeAndNil(PD);
end;
end;
我想要填充整个图像,包括中间部分。有谁知道如何做到这一点(请记住,我的现实生活情况比这个简单的十字更复杂,但它们在任何情况下都是叠加的)各种尺寸的矩形)。我希望能够在 TPathData 对象中创建图像,无需进一步调整即可打印。 预先感谢。
赋予每条路径自己的
TPathData
。
procedure TForm3.Button1Click(Sender: TObject);
var PD1, PD2: TPathData;
aRect1, aRect2: TRectF;
begin
aRect1 := RectF(45,10,55,90);
aRect2 := RectF(10,45,90,55);
PD1 := TPathData.Create;
PD2 := TPathData.Create;
PD1.MoveTo(aRect1.TopLeft);
PD1.LineTo(PointF(aRect1.Right,aRect1.Top));
PD1.LineTo(PointF(aRect1.Right,aRect1.Bottom));
PD1.LineTo(PointF(aRect1.Left,aRect1.Bottom));
PD1.LineTo(aRect1.TopLeft);
PD2.MoveTo(aRect2.TopLeft);
PD2.LineTo(PointF(aRect2.Right,aRect2.Top));
PD2.LineTo(PointF(aRect2.Right,aRect2.Bottom));
PD2.LineTo(PointF(aRect2.Left,aRect2.Bottom));
PD2.LineTo(aRect2.TopLeft);
ImageControl1.Bitmap.SetSize(Round(ImageControl1.BoundsRect.Width), Round(ImageControl1.BoundsRect.Height));
if ImageControl1.Bitmap.Canvas.BeginScene then
try
with ImageControl1.Bitmap.Canvas do
begin
clear(0);
Fill.Kind := TBrushKind.Solid;
Fill.Color := TAlphaColorRec.Black;
Stroke.Thickness := 1;
DrawPath(PD1,1);
FillPath(PD1,1);
DrawPath(PD2,1);
FillPath(PD2,1);
end;
finally
ImageControl1.Bitmap.Canvas.EndScene;
PD1.Free;
PD2.Free;
end;
end;