gpt4 book ai didi

delphi - Windows XP 上的 FireMonkey Canvas.DrawLine

转载 作者:行者123 更新时间:2023-12-03 15:55:12 26 4
gpt4 key购买 nike

如何画一条线?此代码不显示任何内容:

var my_point_1, my_point_2: tPointF;

Canvas.Stroke.Color := claBlue;
Canvas.Stroke.Kind:= tBrushKind.bkSolid;

my_point_1.X:= 100;
my_point_1.Y:= 100;
my_point_2.X:= 120;
my_point_2.Y:= 150;

Canvas.BeginScene;
Canvas.DrawLine(my_point_1, my_point_2, 1.0);
Canvas.EndScene;

Windows XP Service Pack 3(tOsVersion.ToString 为“版本 5.1,Build 2600,32 位版本”,已安装 Delphi XE2 更新 1)

最佳答案

您希望这很容易 - 正如我所做的那样。然而事实并非如此。 FireMonkey 还处于早期阶段,Embarcadero 似乎对反馈感到不知所措。

当直接在 TForm 上使用 Canvas 时,您必须接受结果是不稳定的,即它会在第一次重新绘制(调整大小、其他窗口重叠等)时消失。

这对我来说适用于多台机器:

创建一个新的 FM-HD 项目,添加一个按钮和一个处理程序:

procedure TForm1.Button1Click(Sender: TObject);
var pt0,pt1 : TPointF;
begin
pt0.Create(0,0);
pt1.Create(100,50);
Canvas.BeginScene;
Canvas.DrawLine(pt0,pt1,1);
Canvas.EndScene;
end;

运行,单击按钮,然后(希望如此):瞧!

然而,在 TImage Canvas 上,它稍微复杂一些(阅读:buggy?)

创建一个新项目,这次是两个 TButton 和一个 TImage - 将 (left,top) 设置为 (150,150) 之类的值,以将其 Canvas 与 TForm 的 Canvas 区分开来。

添加此代码并分配给处理程序(双击表单和按钮):

procedure TForm1.FormCreate(Sender: TObject);
begin
// Without this, you normally get a runtime exception in the Button1 handler
Image1.Bitmap := TBitmap.Create(150,150);
end;

procedure TForm1.Button1Click(Sender: TObject);
var pt0,pt1 : TPointF;
begin
pt0.Create(0,100);
pt1.Create(50,0);
with Image1.Bitmap do begin
Canvas.BeginScene;
Canvas.DrawLine(pt0,pt1,1);
BitmapChanged; // without this, no output
Canvas.EndScene;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
// This demonstrates that if you try to access the Canvas of the TImage object (and NOT its bitmap)
// you are sometimes defaulted to the Canvas of the Form (on some configurations you get the line directly on the form).
var pt0,pt1 : TPointF;
begin
pt0.Create(0,100);
pt1.Create(50,0);
with Image1 do begin
Canvas.BeginScene;
Canvas.DrawLine(pt0,pt1,1);
Canvas.EndScene;
end;
end;

最后一点:一旦开始使用位图的 ScanLine 属性,请确保在 BeginScend/EndScene 部分之外进行操作 - 完成后,创建一个“虚拟”BeginScend/EndScene 部分确保您的更改不会丢失:-(如果有必要,我有时可能会回到这个话题;o)

祝你好运!卡斯滕

关于delphi - Windows XP 上的 FireMonkey Canvas.DrawLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7579727/

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