Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:07:21+00:00 2026-06-03T21:07:21+00:00

I haven’t find a function to get a screenshot in FMX.Platform (anyway, nowhere else…).

  • 0

I haven’t find a function to get a screenshot in FMX.Platform (anyway, nowhere else…).

With the VCL, there are many answers (stackoverflow, google, …).

But how to get a screenshot in an image(bitmap or whatever) for Windows and Mac OS X?

Regards,

W.

Update:
The link from Tipiweb gives a good solution for OS X.

Regarding the Windows part: I have coded this, but I don’t like to use the VCL, and a Stream to achieve it…
Any better suggestion, comments?

Thanks.

W.

uses ..., FMX.Types, Winapi.Windows, Vcl.Graphics;

...

function DesktopLeft: Integer;
begin
  Result := GetSystemMetrics(SM_XVIRTUALSCREEN);
end;

function DesktopWidth: Integer;
begin
  Result := GetSystemMetrics(SM_CXVIRTUALSCREEN);
end;

function DesktopTop: Integer;
begin
  Result := GetSystemMetrics(SM_YVIRTUALSCREEN);
end;

function DesktopHeight: Integer;
begin
  Result := GetSystemMetrics(SM_CYVIRTUALSCREEN);
end;


procedure GetScreenShot(var dest: FMX.Types.TBitmap);
var
  cVCL  : Vcl.Graphics.TCanvas;
  bmpVCL: Vcl.Graphics.TBitmap;
  msBmp : TMemoryStream;
begin
  bmpVCL      := Vcl.Graphics.TBitmap.Create;
  cVCL        := Vcl.Graphics.TCanvas.Create;
  cVCL.Handle := GetWindowDC(GetDesktopWindow);
  try
    bmpVCL.Width := DesktopWidth;
    bmpVCL.Height := DesktopHeight;
    bmpVCL.Canvas.CopyRect(Rect(0, 0, DesktopWidth, DesktopHeight),
                           cVCL,
                           Rect(DesktopLeft, DesktopTop, DesktopLeft + DesktopWidth, DesktopTop + DesktopHeight)
                          );
  finally
    ReleaseDC(0, cVCL.Handle);
    cVCL.Free;
  end;

  msBmp := TMemoryStream.Create;
  try
    bmpVCL.SaveToStream(msBmp);
    msBmp.Position := 0;
    dest.LoadFromStream(msBmp);
  finally
    msBmp.Free;
  end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:07:23+00:00Added an answer on June 3, 2026 at 9:07 pm

    I build a small application to take screenshot (Windows / Mac) and it works 🙂 !

    For windows and Mac compatibility, I use a stream.

    API Mac Capture –> TStream

    API Windows Capture –> Vcl.Graphics.TBitmap –> TStream.

    After that, I load my Windows or Mac TStream in a FMX.Types.TBitmap (with load from stream)

    Windows Unit code :

    unit tools_WIN;
    
    interface
    {$IFDEF MSWINDOWS}
    uses Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF}, System.SysUtils, FMX.Types, VCL.Forms, VCL.Graphics;
    
    
      procedure TakeScreenshot(Dest: FMX.Types.TBitmap);
    {$ENDIF MSWINDOWS}
    
    implementation
    
    {$IFDEF MSWINDOWS}
    
    
    procedure WriteWindowsToStream(AStream: TStream);
    var
      dc: HDC; lpPal : PLOGPALETTE;
      bm: TBitMap;
    begin
    {test width and height}
      bm := TBitmap.Create;
    
      bm.Width := Screen.Width;
      bm.Height := Screen.Height;
    
      //get the screen dc
      dc := GetDc(0);
      if (dc = 0) then exit;
     //do we have a palette device?
      if (GetDeviceCaps(dc, RASTERCAPS) AND RC_PALETTE = RC_PALETTE) then
      begin
        //allocate memory for a logical palette
        GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
        //zero it out to be neat
        FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)), #0);
        //fill in the palette version
        lpPal^.palVersion := $300;
        //grab the system palette entries
        lpPal^.palNumEntries :=GetSystemPaletteEntries(dc,0,256,lpPal^.palPalEntry);
        if (lpPal^.PalNumEntries <> 0) then
        begin
          //create the palette
          bm.Palette := CreatePalette(lpPal^);
        end;
        FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
      end;
      //copy from the screen to the bitmap
      BitBlt(bm.Canvas.Handle,0,0,Screen.Width,Screen.Height,Dc,0,0,SRCCOPY);
    
      bm.SaveToStream(AStream);
    
      FreeAndNil(bm);
      //release the screen dc
      ReleaseDc(0, dc);
    end;
    
    
    procedure TakeScreenshot(Dest: FMX.Types.TBitmap);
    var
      Stream: TMemoryStream;
    begin
      try
        Stream := TMemoryStream.Create;
        WriteWindowsToStream(Stream);
        Stream.Position := 0;
        Dest.LoadFromStream(Stream);
      finally
        Stream.Free;
      end;
    end;
    
    {$ENDIF MSWINDOWS}
    end.
    

    Mac Unit Code :

    unit tools_OSX;
    
    
    interface
    {$IFDEF MACOS}
    uses
    
      Macapi.CoreFoundation, Macapi.CocoaTypes, Macapi.CoreGraphics, Macapi.ImageIO,
      FMX.Types,
      system.Classes, system.SysUtils;
    
      procedure TakeScreenshot(Dest: TBitmap);
    {$ENDIF MACOS}
    
    implementation
    {$IFDEF MACOS}
    
    {$IF NOT DECLARED(CGRectInfinite)}
    const
      CGRectInfinite: CGRect = (origin: (x: -8.98847e+30; y: -8.98847e+307);
        size: (width: 1.79769e+308; height: 1.79769e+308));
    {$IFEND}
    
    
    function PutBytesCallback(Stream: TStream; NewBytes: Pointer;
      Count: LongInt): LongInt; cdecl;
    begin
      Result := Stream.Write(NewBytes^, Count);
    end;
    
    procedure ReleaseConsumerCallback(Dummy: Pointer); cdecl;
    begin
    end;
    
    procedure WriteCGImageToStream(const AImage: CGImageRef; AStream: TStream;
      const AType: string = 'public.png'; AOptions: CFDictionaryRef = nil);
    var
      Callbacks: CGDataConsumerCallbacks;
      Consumer: CGDataConsumerRef;
      ImageDest: CGImageDestinationRef;
      TypeCF: CFStringRef;
    begin
      Callbacks.putBytes := @PutBytesCallback;
      Callbacks.releaseConsumer := ReleaseConsumerCallback;
      ImageDest := nil;
      TypeCF := nil;
      Consumer := CGDataConsumerCreate(AStream, @Callbacks);
      if Consumer = nil then RaiseLastOSError;
      try
        TypeCF := CFStringCreateWithCharactersNoCopy(nil, PChar(AType), Length(AType),
          kCFAllocatorNull); //wrap the Delphi string in a CFString shell
        ImageDest := CGImageDestinationCreateWithDataConsumer(Consumer, TypeCF, 1, AOptions);
        if ImageDest = nil then RaiseLastOSError;
        CGImageDestinationAddImage(ImageDest, AImage, nil);
        if CGImageDestinationFinalize(ImageDest) = 0 then RaiseLastOSError;
      finally
        if ImageDest <> nil then CFRelease(ImageDest);
        if TypeCF <> nil then CFRelease(TypeCF);
        CGDataConsumerRelease(Consumer);
      end;
    end;
    
    procedure TakeScreenshot(Dest: TBitmap);
    var
      Screenshot: CGImageRef;
      Stream: TMemoryStream;
    begin
      Stream := nil;
      ScreenShot := CGWindowListCreateImage(CGRectInfinite,
        kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
      if ScreenShot = nil then RaiseLastOSError;
      try
        Stream := TMemoryStream.Create;
        WriteCGImageToStream(ScreenShot, Stream);
        Stream.Position := 0;
        Dest.LoadFromStream(Stream);
      finally
        CGImageRelease(ScreenShot);
        Stream.Free;
      end;
    end;
    
    
    
     {$ENDIF MACOS}
    end.
    

    In your mainForm unit :

    ...
    {$IFDEF MSWINDOWS}
      uses tools_WIN;
    {$ELSE}
      uses tools_OSX;
    {$ENDIF MSWINDOWS}
    
    ...
    var
      imgDest: TImageControl;
    ...
    TakeScreenshot(imgDest.Bitmap);
    

    If you have another idea, please talk to me 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't browsed through the spec, though I doubt any info is in there.
I haven't been able to find any documentation on Android's sync services, so far
I haven't been able to get any more console output (to help with debugging)
I haven't been able to find any real documentation on this, so I'm wondering
I haven't seen this question anywhere else, I hope someone can help. I have
I haven't worked with SQL Reporting much, however I have been trying to get
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Haven't seen many Geneva related questions yet, I have posted this question in the
I haven't been able to find what these Xcode icons mean. Some you can
I haven't been able to find authorative explanations, microformats or guidelines for the following,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.