改变形状的方向

Gle*_*rse 2 delphi vcl

我想知道是否有办法改变TShape的方向,而不是方形,我想旋转它看起来像一个钻石..

如果不是TShape的方式,怎么办呢?

pau*_*sm4 8

Delphi TShape只不过是绘制了一堆矢量图形.

您可以使用二维变换矩阵"旋转"X/Y坐标本身.计算机图形学101:

  • +1; 关于2D变换的良好参考.第二个是非常直观的. (6认同)

Rem*_*eau 5

TShape本身不能旋转.但是你可以使用TPaintBox来绘制自己想要的图形,这只是在数学上绘制点之间绘制的点.例如:

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  Points: array[0..3] of TPoint;
  W, H: Integer;
begin
  W := PaintBox1.Width;
  H := PaintBox1.Height;

  Points[0].X := W div 2;
  Points[0].Y := 0;

  Points[1].X := W;
  Points[1].Y := H div 2;

  Points[2].X := Points[0].X;
  Points[2].Y := H;

  Points[3].X := 0;
  Points[3].Y := Points[1].Y;

  PaintBox1.Canvas.Brush.Color := clBtnFace;
  PaintBox1.Canvas.FillRect(Rect(0, 0, W, H));

  PaintBox1.Canvas.Brush.Color := clBlue;
  PaintBox1.Canvas.Pen.Color := clBlack;
  PaintBox1.Canvas.Pen.Width := 1;
  PaintBox1.Canvas.Polygon(Points);
end;
Run Code Online (Sandbox Code Playgroud)