在 Firemonkey 组件中旋转时如何避免重复图像?
How to avoid duplicate image when rotated in Firemonkey component?
我做了什么?
我正在尝试开发 FMX Gauge 组件。目前它只有一根针。我创建了一个新包并添加了以下代码:
单位 FMX.VDO;
interface
uses
System.SysUtils,
System.Classes,
FMX.Types,
FMX.Controls,
FMX.MultiResBitmap,
FMX.Layouts,
FMX.Objects;
type
TVdoLayout = class(TScaledLayout)
private
FNeedle : TImage;
function GetBitMapNeedle: TFixedMultiResBitmap;
procedure SetBitMapNeedle(const Value: TFixedMultiResBitmap);
function GetValue: Double;
procedure SetValue(const Value: Double);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property BitMapNeedle : TFixedMultiResBitmap read GetBitMapNeedle write SetBitMapNeedle;
property Value : Double read GetValue write SetValue;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TVdoLayout]);
end;
{ TVdoLayout }
constructor TVdoLayout.Create(AOwner: TComponent);
begin
inherited;
Self.Size.Width := 326;
Self.Size.Height := Self.Size.Width;
FNeedle := TImage.Create(Self);
FNeedle.Parent := Self;
FNeedle.Width := 262;
FNeedle.Height := 21;
FNeedle.Position.X := 40;
FNeedle.Position.Y := 270;
FNeedle.Height := Self.Height * 0.04901;
FNeedle.Width := Self.Width * 0.7485;
FNeedle.RotationCenter.X := 0.935;
FNeedle.RotationCenter.Y := 0.27;
FNeedle.RotationAngle := 45;
end;
function TVdoLayout.GetBitMapNeedle: TFixedMultiResBitmap;
begin
Result := FNeedle.MultiResBitmap;
end;
procedure TVdoLayout.SetBitMapNeedle(const Value: TFixedMultiResBitmap);
begin
FNeedle.MultiResBitmap := Value;
end;
function TVdoLayout.GetValue: Double;
begin
Result := FNeedle.RotationAngle;
end;
procedure TVdoLayout.SetValue(const Value: Double);
begin
FNeedle.RotationAngle := Value;
end;
end.
在此之后,我构建了项目并安装了我的组件。
我创建了一个新的 FMX 项目并放置了我的组件。我在设计时加载了一张针的图片。见下文:
在设计时我可以更改 属性 Value
。如果你看到上面的代码,Value
改变了针的 RotationAngle
。它在设计时完美运行。
有什么问题?
在 运行 时间里,当我通过 TEdit 将我的组件的 Value
属性 更改为 90 时它起作用了,但是拍摄了初始针的快照,看起来重复如下所示:
我尝试过但没有成功的其他事情?
我试过调用调整大小和重绘函数。
还按照@UweRaabe 的建议在创建期间添加了 FNeedle.SetSubComponent(True);
。
如果我在 运行 时间加载针图像,它就会工作。但这不是一个理想的解决方案。
详情
- Delphi 10.1 柏林
- FireMonkey(在 Windows 上)
在我的搜索中,我在这里找到了解决方案:
我只需要将 属性 Stored
设置为 False
。见下文:
FNeedle.Stored := false;
我做了什么?
我正在尝试开发 FMX Gauge 组件。目前它只有一根针。我创建了一个新包并添加了以下代码: 单位 FMX.VDO;
interface
uses
System.SysUtils,
System.Classes,
FMX.Types,
FMX.Controls,
FMX.MultiResBitmap,
FMX.Layouts,
FMX.Objects;
type
TVdoLayout = class(TScaledLayout)
private
FNeedle : TImage;
function GetBitMapNeedle: TFixedMultiResBitmap;
procedure SetBitMapNeedle(const Value: TFixedMultiResBitmap);
function GetValue: Double;
procedure SetValue(const Value: Double);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property BitMapNeedle : TFixedMultiResBitmap read GetBitMapNeedle write SetBitMapNeedle;
property Value : Double read GetValue write SetValue;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TVdoLayout]);
end;
{ TVdoLayout }
constructor TVdoLayout.Create(AOwner: TComponent);
begin
inherited;
Self.Size.Width := 326;
Self.Size.Height := Self.Size.Width;
FNeedle := TImage.Create(Self);
FNeedle.Parent := Self;
FNeedle.Width := 262;
FNeedle.Height := 21;
FNeedle.Position.X := 40;
FNeedle.Position.Y := 270;
FNeedle.Height := Self.Height * 0.04901;
FNeedle.Width := Self.Width * 0.7485;
FNeedle.RotationCenter.X := 0.935;
FNeedle.RotationCenter.Y := 0.27;
FNeedle.RotationAngle := 45;
end;
function TVdoLayout.GetBitMapNeedle: TFixedMultiResBitmap;
begin
Result := FNeedle.MultiResBitmap;
end;
procedure TVdoLayout.SetBitMapNeedle(const Value: TFixedMultiResBitmap);
begin
FNeedle.MultiResBitmap := Value;
end;
function TVdoLayout.GetValue: Double;
begin
Result := FNeedle.RotationAngle;
end;
procedure TVdoLayout.SetValue(const Value: Double);
begin
FNeedle.RotationAngle := Value;
end;
end.
在此之后,我构建了项目并安装了我的组件。
我创建了一个新的 FMX 项目并放置了我的组件。我在设计时加载了一张针的图片。见下文:
在设计时我可以更改 属性 Value
。如果你看到上面的代码,Value
改变了针的 RotationAngle
。它在设计时完美运行。
有什么问题?
在 运行 时间里,当我通过 TEdit 将我的组件的 Value
属性 更改为 90 时它起作用了,但是拍摄了初始针的快照,看起来重复如下所示:
我尝试过但没有成功的其他事情?
我试过调用调整大小和重绘函数。
还按照@UweRaabe 的建议在创建期间添加了 FNeedle.SetSubComponent(True);
。
如果我在 运行 时间加载针图像,它就会工作。但这不是一个理想的解决方案。
详情
- Delphi 10.1 柏林
- FireMonkey(在 Windows 上)
在我的搜索中,我在这里找到了解决方案:
我只需要将 属性 Stored
设置为 False
。见下文:
FNeedle.Stored := false;