在Firemonkey组件中旋转时如何避免重复图像?

时间:2018-08-15 13:43:32

标签: delphi components firemonkey

我做了什么?

我正在尝试开发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项目并放置了我的组件。我在设计时加载了针的图片。参见下文:

Needle run time

在设计时,我可以更改属性Value。如果您看到上面的代码,则Value会改变针的RotationAngle。它在设计时完美运行。

出什么问题了?

在运行时,当我通过TEdit将组件的Value属性更改为90时,它可以工作,但是拍摄了初始针的快照,并且看起来像是重复的,如下所示:

{{3}}

我尝试过的其他没有成功的事情吗?

我试图调用调整大小和重新绘制函数。 还建议在创建过程中按照{UweRaabe的建议添加FNeedle.SetSubComponent(True);。 如果我在运行时加载针图像,它将起作用。但这不是理想的解决方案。

详细信息

  • 德尔福10.1柏林
  • FireMonkey(在Windows上)

1 个答案:

答案 0 :(得分:1)

在搜索中,我在这里找到了解决方案:Firemonkey: How to define a component that contain another component?

我只需将属性Stored设置为False。见下文:

FNeedle.Stored := false;