Setting the Line End Styles for Canvas.LineTo

大憨熊 提交于 2019-12-19 08:01:14

问题


Is there any way to set the style for the lineends for the TCanvas.LineTo method? It seems to default to rounded ends, which looks very bad for several lines in a row of different colours when Pen.Width is set to a large value (e.g. 9).

It looks like this (rounded ends):

 ********........******
**********........******
**********........******
 ********........******

(where * is e.g. blue and . is yellow)

It is even worse if the two outer lines are drawn after the middle line:

 ********........******
**********......********
**********......********
 ********........******

I'd like it to look like this (streight ends):

 ********........******
 ********........******
 ********........******
 ********........******

Pen does not seem to offer any setting for this and neither does the LineTo method. Is there maybe a windows API function I could call?


回答1:


Maybe ExtCreatePen helps. Check the PS_ENDCAP_* and PS_JOIN_* flags.




回答2:


Sample code from DelphiPraxis forum (German language)

procedure TForm1.FormCreate(Sender: TObject);
   var LogBrush:TLOGBRUSH;
begin
   ZeroMemory(@LogBrush, SizeOf(LogBrush));
   LogBrush.lbColor:=ColorToRGB(Canvas.Pen.Color);
   LogBrush.lbHatch:=0;

   DeleteObject(Canvas.Pen.Handle);
   Canvas.Pen.Handle:=ExtCreatePen(PS_Geometric or PS_Solid or PS_EndCap_Square or PS_Join_Miter, 10, LogBrush, 0, nil);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
   Canvas.MoveTo(0, 0);
   Canvas.LineTo(50, 50);
end; 


来源:https://stackoverflow.com/questions/368432/setting-the-line-end-styles-for-canvas-lineto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!