I created this function on DELPHI XE5, it's work very well. You create a single image with all your icons, you load this image in a TBitmap (IDE in my exemple), and you create a lot of small TRECTANGLE in the form.
During the onCreate, i call Mapping method to set the background of each Trectangle.
BUT IN DELPHI XE8, It's not working on ANDROID
This is the mapping function.
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;
The picture (delphiXE.png) is deploying in "asset/internal", and opening in 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;
In Windows, everythings works fine, but no in Android, but if i add a simple onclick event with Mapping(Logo,0,0); call, the mapping work, but i need to click first on the grey Trectangle to set it background
Any idea ?
UPDATED : Using a Timer, the mapping function is working and the trectangle have the good picture, but if i switch to another application and go back to my application, the picture disappear and the Trectangle turn back to solid gray.
That mean that the internal paint of the TRectangle is not updated. Why ?
Thanks for you help, i find a solution and the origin of the problem.
The fact that the picture in the Trectangle was not persistent help me.
//Assign Crop image to Rectangle objects
Obj.Fill.Bitmap.Bitmap.Assign(FBitmap);
is no longer working like it worked on DELPHI XE5 on Android. It 's copy the bitmap but not on a persistent way. This is why it's working with onclick, but disappear when i switch application.
So, I changed this line by
// 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);
and in my TEST PROJECT, it's working.
I hope this can help another developper.