DELPHI XE8:OnCreate事件期间未刷新Android上的TRectangle

莱昂内尔·西罗(Lionel siero)

我在DELPHI XE5上创建了此功能,效果很好。您创建一个包含所有图标的图像,将该图像加载到TBitmap中(以IDE为例),然后在表单中创建许多小的TRECTANGLE。

在onCreate期间,我调用Mapping方法来设置每个Trectangle的背景。

但是在DELPHI XE8中,它在ANDROID上不起作用

这是映射功能。

Procedure TForm1.Mapping(Const Obj:TRectangle;Const ofx,ofy:Integer);
Var
  Arect    : TRectF;
  FBitmap  : TBitmap;
Begin
  Arect:=TRectF.Create(0,0,Obj.Width,Obj.Height);
  Obj.Stroke.Kind := TBrushKind.None;
  Obj.Fill.Kind   := TBrushKind.Bitmap;
  Obj.Fill.Bitmap.WrapMode := TWrapMode.TileOriginal;
 //Create Crop Bitmap
  FBitmap:=TBitmap.create( Round(Obj.Width), Round(Obj.Height)) ;
   Try
    FBitmap.Canvas.BeginScene();
    FBitmap.Canvas.ClearRect(ARect,StringToAlphaColor('$00000000'));
    FBitmap.Canvas.DrawBitmap(IDE,
                        TRectF.Create(ofx,ofy,ofx+Obj.Width,ofy+Obj.Height),
                                Arect, 100) ;
    FBitmap.Canvas.EndScene;
    //Assign  Crop  image to Rectangle object 
    Obj.Fill.Bitmap.Bitmap.Assign(FBitmap);

   Finally
    FBitmap.Free;
   End;
End;

图片(delphiXE.png)正在“资产/内部”部署,并在oncreate中打开。

procedure TForm1.FormCreate(Sender: TObject);
Var  Mfile:String;
begin
  IDE := TBitmap.Create(ClientWidth,ClientHeight);
 {$IFDEF ANDROID}
  Mfile:=TPath.Combine(TPath.GetDocumentsPath, 'delphiXE.png');
 {$ELSE}
  Mfile:=TPath.Combine(ExtractFilePath(ParamStr(0)), 'delphiXE.png');
 {$ENDIF}
  If FileExists(MFile)
  Then begin
       IDE.LoadFromFile(MFile);
       Mapping(Logo,0,0);
       End
  Else ShowMessage('NO '+MFile);
end;

在Windows中,一切正常,但在Android中则没有,但是如果我使用Mapping(Logo,0,0)添加一个简单的onclick事件;调用,映射工作,但我需要先在灰色的Trectangle上单击以将其设置为背景

任何的想法 ?

更新:使用计时器,映射功能正在运行,并且矩形具有良好的图片,但是如果我切换到另一个应用程序并返回到我的应用程序,则图片消失,并且矩形变为纯灰色。

这意味着TRectangle的内部绘制不会更新。为什么 ?

莱昂内尔·西罗(Lionel siero)

感谢您的帮助,我找到了解决方案和问题的根源。

Trectangle中的图片并不持久的事实帮助了我。

//Assign  Crop  image to Rectangle objects 
Obj.Fill.Bitmap.Bitmap.Assign(FBitmap);

不再像在Android上的DELPHI XE5上工作一样。它复制位图,但不是持久的方式。这就是为什么它与onclick一起使用的原因,但是当我切换应用程序时消失了。

所以,我改变了这一行

// Force the size of TRectangle internal Bitmap
Obj.Fill.Bitmap.Bitmap.SetSize(FBitmap.Width,FBitmap.Height);
// Copy the crop bitmap in TRectangle Internal Bitmap
Obj.Fill.Bitmap.Bitmap.CopyFromBitmap(FBitmap);

在我的“测试项目”中,它正在运行。

我希望这可以帮助另一位开发人员。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章