我尝试制作一个绘制2个正弦波的应用程序,并在第3个TImage屏幕上绘制这两个正弦波的总和... 我的机器人上有黑屏,有时“应用程序停止响应”。 代码是:
unit lenovoEx1;
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;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
Panel1: TPanel;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
TrackBar3: TTrackBar;
Panel2: TPanel;
TrackBar4: TTrackBar;
TrackBar5: TTrackBar;
TrackBar6: TTrackBar;
procedure TrackBar2Change(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar3Change(Sender: TObject);
procedure TrackBar5Change(Sender: TObject);
procedure TrackBar4Change(Sender: TObject);
procedure TrackBar6Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Point1 : TPoint;
brush_T : TStrokeBrush;
bitmap_T : TBitmap;
rectf_T : TRectF;
procedure DrawSine(Image: TImage; Amp, Pha, Fre : Single);
procedure DrawSum(Image: TImage; Amp1, Pha1, Fre1, Amp2, Pha2, Fre2 : Single);
procedure Trigger(Sender: TObject);
procedure ZeroSettings();
public
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Trigger(Sender: TObject);
var
ampl1, ampl2, phas1, phas2, freq1, freq2 : Single;
begin
ampl1 := Form1.TrackBar1.Value;
phas1 := Form1.TrackBar2.Value;
freq1 := Form1.TrackBar3.Value;
ampl2 := Form1.TrackBar4.Value;
phas2 := Form1.TrackBar5.Value;
freq2 := Form1.TrackBar6.Value;
Form1.DrawSine(Form1.Image1,ampl1,phas1,freq1);
Form1.DrawSine(Form1.Image2,ampl2,phas2,freq2);
Form1.DrawSum(Form1.Image3,ampl1,phas1,freq1,ampl2,phas2,freq2);
end;
procedure TForm1.ZeroSettings();
begin
Form1.TrackBar1.Value := 50;
Form1.TrackBar2.Value := 50;
Form1.TrackBar3.Value := 50;
Form1.TrackBar4.Value := 50;
Form1.TrackBar5.Value := 50;
Form1.TrackBar6.Value := 50;
end;
procedure TForm1.DrawSine(Image: TImage; Amp, Pha, Fre: Single);
var
width, height, I : Integer;
sin_T : Extended;
Point2 : TPoint;
begin
width := Round(Image.Width);
height := Round(Image.Height);
bitmap_T.SetSize(width, height);
rectf_T.Width := width;
rectf_T.Height := height;
Image.Bitmap.Canvas.BeginScene;
Image.Bitmap := bitmap_T;
Image.Bitmap.Canvas.SetMatrix(TMatrix.CreateScaling(1.0 / Canvas.Scale, 1.0 / Canvas.Scale) * Canvas.Matrix);
Image.Bitmap.Canvas.ClearRect(rectf_T, TAlphaColorRec.Black );
for I := 0 to width do
begin
sin_T := Sin(((I - Pha)/200.0) * Fre);
Point2.X := Round(I);
Point2.Y := Round(sin_T * Amp) + Round(height/2.0);
if I = 0 then
begin
Point1.X := Round(I);
Point1.Y := Round(sin_T * Amp) + Round(height/2.0);
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
end
else
begin
if I = width then
begin
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
Point1.X := Round(I);
Point1.Y := Round(height/2.0);
end
else
begin
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
Point1.X := Point2.X;
Point1.Y := Point2.Y;
end;
end;
end;
Image.Bitmap.Canvas.EndScene();
end;
procedure TForm1.DrawSum(Image: TImage; Amp1, Pha1, Fre1, Amp2, Pha2, Fre2: Single);
var
width, height, I : Integer;
sin_T1, sin_T2 : Extended;
Point2 : TPoint;
begin
width := Round(Image.Width);
height := Round(Image.Height);
bitmap_T.SetSize(width, height);
rectf_T.Width := width;
rectf_T.Height := height;
Image.Bitmap.Canvas.BeginScene;
Image.Bitmap := bitmap_T;
Image.Bitmap.Canvas.SetMatrix(TMatrix.CreateScaling(1.0 / Canvas.Scale, 1.0 / Canvas.Scale) * Canvas.Matrix);
Image.Bitmap.Canvas.ClearRect(rectf_T, TAlphaColorRec.Black );
for I := 0 to width do
begin
sin_T1 := Sin(((I)/200.0) * Fre1);
sin_T2 := Sin(((I)/200.0) * Fre2);
Point2.X := Round(I);
Point2.Y := Round(sin_T1 * Amp1) + Round(sin_T2 * Amp2) + Round(height/2.0);
if I = 0 then
begin
Point1.X := I;
Point1.Y := Round((sin_T1 * Amp1) + (sin_T2 * Amp2)) + Round(height/2.0);
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
end
else
begin
if I = width then
begin
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
Point1.X := Round(I);
Point1.Y := Round(height/2.0);
end
else
begin
Image.Bitmap.Canvas.DrawLine(Point1, Point2, 1.0, brush_T);
Point1.X := Point2.X;
Point1.Y := Point2.Y;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ZeroSettings();
brush_T := TStrokeBrush.Create(TBrushKind.bkSolid, TAlphaColorRec.White);
bitmap_T := TBitmap.Create(10,10);
rectf_T := TRectF.Create(0, 0, 1, 1);
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Trigger(Sender);
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
begin
Trigger(Sender);
end;
procedure TForm1.TrackBar3Change(Sender: TObject);
begin
Trigger(Sender);
end;
procedure TForm1.TrackBar4Change(Sender: TObject);
begin
Trigger(Sender);
end;
procedure TForm1.TrackBar5Change(Sender: TObject);
begin
Trigger(Sender);
end;
procedure TForm1.TrackBar6Change(Sender: TObject);
begin
Trigger(Sender);
end;
end.
我看不到任何可能有错误的地方......如果oyu看到奇怪的事情,请帮忙。我不想在Delphi中禁食......
答案 0 :(得分:0)
是否已禁用睡眠模式?
禁用睡眠模式。 去开发者选项 - >并检查“保持清醒”选项