gpt4 book ai didi

android - 德尔福XE8 : No refresh for TRectangle on Android during OnCreate event

转载 作者:行者123 更新时间:2023-11-29 17:38:34 25 4
gpt4 key购买 nike

我在 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)正在“asset/internal”中部署,并在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 的内部绘制没有更新。为什么?

最佳答案

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

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);

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

我希望这可以帮助其他开发者。

关于android - 德尔福XE8 : No refresh for TRectangle on Android during OnCreate event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29584789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com