gpt4 book ai didi

delphi - 在 Canvas 上绘制表单路径

转载 作者:行者123 更新时间:2023-12-03 03:22:45 27 4
gpt4 key购买 nike

如何使用路径绘制这样的表单:

Expected result

沿相反方向绘制圆弧会产生错误的效果。有人可能有一个想法。显然已经考虑了此举。

Rreceived result

代码:



procedure TForm1.PaintBox1Paint(Sender: TObject);
var
iTop, iHeight: Integer;
iLeft,iWidth : Integer;
iC: Integer;
h,w: Integer;
Canvas: TCanvas;

procedure DrawPathEnveloppeExt(ACanvas: TCanvas; const AiLeft, AiTop, AiRight, AiBottom, AiC: Integer; AiPivotX, AiPivotY: Integer);
begin
ACanvas.MoveTo(AiLeft,AiTop + AiC);
ACanvas.LineTo(AiLeft,AiBottom - AiC);
ACanvas.ArcTo( AiLeft, AiBottom -(AiC*2), AiLeft + (AiC*2), AiBottom, AiLeft, AiBottom - AiC, AiLeft + AiC,AiBottom );
ACanvas.LineTo(AiPivotX-AiC,AiBottom);
ACanvas.ArcTo(AiPivotX-(2*AiC),AiBottom -(2*AiC), AiPivotX, AiBottom, AiPivotX - AiC, AiBottom, AiPivotX, AiBottom - AiC);
ACanvas.LineTo(AiPivotX ,AiPivotY + (AiC));
ACanvas.MoveTo(AiPivotX + AiC, AiPivotY );
ACanvas.Arc(AiPivotX,AiPivotY, AiPivotX + (2*AiC), AiPivotY + (2*AiC), AiPivotX + AiC, AiPivotY, AiPivotX , AiPivotY+ AiC);
ACanvas.MoveTo(AiPivotX + AiC, AiPivotY);
ACanvas.LineTo(AiRight-AiC,AiPivotY);
ACanvas.ArcTo(AiRight-(2*AiC),AiPivotY -(2*AiC),AiRight,AiPivotY, AiRight-AiC,AiPivotY, AiRight,AiPivotY - AiC);
ACanvas.LineTo(AiRight,AiTop + AiC);
ACanvas.ArcTo(AiRight-(AiC*2),AiTop,AiRight,AiTop+(2*AiC),AiRight,AiTop + AiC,AiRight-AiC,AiTop);
ACanvas.LineTo(AiLeft+ AiC,AiTop);
ACanvas.ArcTo(AiLeft,AiTop,AiLeft+(2*AiC),AiTop + (2*AiC), AiLeft + AiC ,AiTop,AiLeft,AiTop+ AiC);
CloseFigure(ACanvas.Handle);
end;


begin
h := PaintBox1.ClientHeight;
w := PaintBox1.ClientWidth;

iC := 15;
iTop := 35;
iHeight := 165;
iLeft := 50;
iWidth := 250;


Canvas := PaintBox1.Canvas;

BeginPath(Canvas.Handle);
DrawPathEnveloppeExt(Canvas, iLeft, iTop, iLeft + iWidth, iTop + iHeight, iC, 200,120);
EndPath(Canvas.Handle);

Canvas.Brush.Color := clLime;
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Width := 2;
Canvas.Pen.Color := clGrayText;
StrokeAndFillPath(PaintBox1.Canvas.Handle);
end;



有什么想法吗?

非常感谢

最佳答案

似乎您已经更改了起点和终点并忽略了圆弧方向。此代码根据需要绘制图形:

ACanvas.LineTo(AiPivotX ,AiPivotY + (AiC)); //6-th line of your procedure

SetArcDirection(ACanvas.Handle, AD_CLOCKWISE);
ACanvas.ArcTo(AiPivotX,AiPivotY, AiPivotX + (2*AiC), AiPivotY + (2*AiC), AiPivotX, AiPivotY + AiC, AiPivotX + AiC , AiPivotY);
SetArcDirection(ACanvas.Handle, AD_COUNTERCLOCKWISE);

ACanvas.LineTo(AiRight-AiC,AiPivotY); //10-th line of your procedure

关于delphi - 在 Canvas 上绘制表单路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46959534/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com