softtouch 9 Posted February 27, 2023 (edited) I am trying to figure out hot to make a screenshot via code of the own app when running on macOS, but could not find a solution. Does anybody here has a clue for me? Windows is no problem, just macOS cause headache. Edited February 27, 2023 by softtouch Share this post Link to post
SwiftExpat 65 Posted February 27, 2023 I use this, you should be able to adapt for your use. RootComponent is a TForm. Reference: https://www.fmxexpress.com/create-device-scaled-screenshots-in-delphi-xe5-firemonkey-on-android-and-ios/ function TSERTTKRepoForm.ScreenShot: TTMSFNCBitmap; var lms: TMemoryStream; bmp: TBitmap; fScreenScale: Single; Surf: TBitmapSurface; function GetScreenScale: Single; var ScreenService: IFMXScreenService; begin result := 1; if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService)) then begin result := ScreenService.GetScreenScale; end; end; begin lms := TMemoryStream.Create; try lms.position := 0; fScreenScale := GetScreenScale; bmp := TBitmap.Create(Round(TForm(RootComponent).Canvas.Width * fScreenScale), Round(TForm(RootComponent).Canvas.Height * fScreenScale)); bmp.Clear(0); if bmp.Canvas.BeginScene then try TForm(RootComponent).PaintTo(bmp.Canvas); finally bmp.Canvas.EndScene; end; Surf := TBitmapSurface.Create; Surf.Assign(bmp); if not TBitmapCodecManager.SaveToStream(lms, Surf, '.png') then raise EBitmapSavingFailed.Create('Error saving Bitmap to png'); Surf.Free; bmp.Free; lms.position := 0; result := TTMSFNCBitmap.CreateFromStream(lms); finally lms.Free; end; end; 1 1 Share this post Link to post
softtouch 9 Posted February 27, 2023 (edited) I will play with it, thanks. Edit: Tested and works just fine 🙂 Edited February 27, 2023 by softtouch Share this post Link to post