如何在Canvas上绘制(android)

时间:2017-08-19 22:30:01

标签: android delphi canvas firemonkey delphi-xe7

我想从另一种方法在画布上绘制一些东西。但我不能。

 unit MainFormUnit;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics,
  FMX.Dialogs, FMX.StdCtrls, FMX.Objects, System.Math.Vectors;

type
  TMainForm = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.fmx}

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
  Canvas.BeginScene;
  Canvas.Fill.Color := $FF111111 + random($FFFFFF);
  Canvas.Fill.Kind := TBrushKind.Solid;
  Canvas.FillRect(RectF(random(300), random(300), random(300), random(300)), 0,
    0, [], 1);
  Canvas.EndScene;
end;

end.

它没有任何吸引力。为什么?请不要在OnPaint方法中使用绘图操作。

1 个答案:

答案 0 :(得分:-1)

  if Canvas.BeginScene the
  begin
    Canvas.Fill.Color := $FF111111 + random($FFFFFF);
    Canvas.Fill.Kind := TBrushKind.Solid;
    Canvas.FillRect(RectF(random(300), random(300), random(300), random(300)), 
    0,
    0, [], 1);
    Canvas.EndScene;
  end;