DELPHI XE8:在 OnCreate 事件期间 Android 上的 TRectangle 没有刷新
DELPHI XE8 : No refresh for TRectangle on Android during OnCreate event
我在 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('[=12=]000000'));
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 的内部绘制没有更新。为什么?
您是否尝试测试 Canvas.BeginScene 的 return ?如果失败,则表示图形上下文系统没有成功初始化。 (是的,这在 XE5 上工作,也许其他工作,想想看,他们可能在某处改变了初始化序列)
创造阶段,当然不会变态。
你应该在别处这样做。
感谢您的帮助,我找到了解决方案和问题的根源。
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);
在我的测试项目中,它正在运行。
希望对其他开发者有所帮助。
我在 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('[=12=]000000'));
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 的内部绘制没有更新。为什么?
您是否尝试测试 Canvas.BeginScene 的 return ?如果失败,则表示图形上下文系统没有成功初始化。 (是的,这在 XE5 上工作,也许其他工作,想想看,他们可能在某处改变了初始化序列) 创造阶段,当然不会变态。 你应该在别处这样做。
感谢您的帮助,我找到了解决方案和问题的根源。
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);
在我的测试项目中,它正在运行。
希望对其他开发者有所帮助。