我没有成功尝试绘制1像素线。我尝试将表单中的QDockWidget* dw = new QDockWidget;
QWidget* tw1 = new TestWidget;
QWidget* tw2 = new TestWidget;
dw->setWidget(tw1);
dw->setWidget(tw2);
tw1->setParent(0);
delete dw; // dw and tw2 deleted here, but not tw1
参数设置为所有三个可用选项,但这不会改变结果:始终获得具有抗锯齿功能的行。相反,不知何故,Quality
类绘制了一个干净的1像素宽度边框,这意味着可以禁用抗锯齿模式。问题是如何。下面是我使用的代码示例:
tRectangle
procedure tMyLine.Paint;
begin
with Canvas do begin
Stroke.Cap := Flat;
Stroke.Color := tAlphaColor.Blue;
Stroke.Join := Miter;
Stroke.Kind := Solid;
Stroke.Thickness := 1;
BeginScene;
DrawLine (tPointF (10, 10), tPointF (100, 10), 1);
EndScene;
end;
end;
小于一个也不起作用。
答案 0 :(得分:1)
使用表单和paintbox的这些设置(偏离默认值): (顺便说一下,使用Delphi 10.1 Berlin,我没有安装东京)
object Form24: TForm24
Left = 0
Top = 0
Caption = 'Form24'
ClientHeight = 216
ClientWidth = 311
Quality = HighPerformance
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object PaintBox1: TPaintBox
Position.X = 8.000000000000000000
Position.Y = 8.000000000000000000
Size.Width = 200.000000000000000000
Size.Height = 200.000000000000000000
Size.PlatformDefault = False
OnPaint = PaintBox1Paint
end
注意:Quality = HighPerformance
,而不是HighQuality
以下代码
procedure TForm24.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
var
a: integer;
begin
Canvas.BeginScene;
try
Canvas.Stroke.Color := TAlphaColorRec.Black;
Canvas.Stroke.Kind := TBrushKind.Solid;
Canvas.Stroke.Dash := TStrokeDash.solid;
for a := 0 to 10 do
Canvas.DrawLine(PointF(a * 20, 0), PointF(a * 20, 200), 1);
for a := 0 to 10 do
Canvas.DrawLine(PointF(0, a * 20 + 0), PointF(200, a * 20), 1);
Canvas.DrawLine(PointF(0, 0), PointF(200, 200), 1);
Canvas.DrawEllipse(RectF(5, 5, 195, 195), 1);
Canvas.Stroke.Dash := TStrokeDash.Solid;
Canvas.Stroke.Color := TAlphaColorRec.Red;
Canvas.DrawRect(RectF(5, 5, 195, 195), 0, 0, [], 1);
finally
Canvas.EndScene;
end;
end;
产生此结果
答案 1 :(得分:0)
通过将坐标设置为整数+ 0.5,我能够对垂直和水平线执行此操作。看来,如果使用整数坐标,则会将线放置在像素边界上,但是通过添加0.5会将线放置在像素的中间。
DrawLine(tPointF(10.5,10.5),tPointF(100.5,10.5),1);