Recent

Author Topic: [SOLVED] Can't take screenshot on Linux with BGRABitmap / With wiki code  (Read 2546 times)

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Hi, this is my code:

Code: Pascal  [Select][+][-]
  1. procedure TfrmSoporte.btnCapturaDePantallaClick(Sender: TObject);
  2. var
  3.   bitmap: TBGRABitmap;
  4. begin
  5.   try
  6.     bitmap := TBGRABitmap.Create;
  7.     try
  8.       Application.Minimize;
  9.       Application.ProcessMessages;
  10.       sleep(1000);
  11.       bitmap.TakeScreenshotOfPrimaryMonitor;
  12.       Application.Restore;
  13.       captura := GetTempDir(False) + FormatDateTime('dd_mm_yyyy_hh_nn_ss', Now) + '.jpg';
  14.       bitmap.SaveToFile(captura);
  15.       ShowMessage(rsCapturaPantalla);
  16.       btnVerCaptura.Enabled := True;
  17.     except
  18.       on E: exception do
  19.       begin
  20.         captura := '';
  21.         ShowMessage(rsErrorCapturaPantalla + LineEnding + e.Message);
  22.       end;
  23.     end;
  24.   finally
  25.     bitmap.Free;
  26.   end;
  27. end;

On Windows works fine.

On Ubuntu it fails showing:
Code: Pascal  [Select][+][-]
  1. Cannot get raw image from device
« Last Edit: March 01, 2018, 05:26:05 pm by lainz »

balazsszekely

  • Guest

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Can't take screenshot on Linux with BGRABitmap
« Reply #2 on: March 01, 2018, 02:56:17 pm »
This works well both on windows and linux: http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen

Thanks. I will try.

Also I must report that BGRABitmap way is not working on macOS:

"Unable to create CGContextRef".

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Can't take screenshot on Linux with BGRABitmap
« Reply #3 on: March 01, 2018, 03:30:37 pm »
This works well both on windows and linux: http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen

Is not working for me on Linux, only Windows. It seems that BGRABitmap is using the wiki code also.

Edit: I'm using Lazarus trunk (1.9) fpc trunk (3.1.1) and for mac and Linux I'm using Virtual Machines. It should work on a VM?

Someone can test on real device?

Edit 2: Tested on a new VM on ElementaryOS and works fine, maybe it's an Ubuntu problem?
« Last Edit: March 01, 2018, 04:30:55 pm by lainz »

balazsszekely

  • Guest
Re: Can't take screenshot on Linux with BGRABitmap / With wiki code
« Reply #4 on: March 01, 2018, 05:13:37 pm »
On Linux Mint 18.3 both your and my code works well(also on wm). Perhaps some libraries are missing on ubuntu?

PS: On OSX none of the above method works.  :( Anyway carbon is fading out fast. I did not try with cocoa.

« Last Edit: March 01, 2018, 05:15:48 pm by GetMem »

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Can't take screenshot on Linux with BGRABitmap / With wiki code
« Reply #5 on: March 01, 2018, 05:25:52 pm »
Thanks for testing, well is nothing we can do =)

I will mark it as solved.

 

TinyPortal © 2005-2018