Recent

Author Topic: take screenshot  (Read 13895 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 392
take screenshot
« on: January 04, 2012, 09:41:23 am »
http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen

great, it takes screenshot, including your form on it. Besides hiding/showing my form in between,
which is ugly, I have no other idea how to take screenshot of everything behind my/focused form ?
lazarus 3.2-fpc-3.2.2-win32/win64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: take screenshot
« Reply #1 on: January 04, 2012, 09:57:31 am »
Sure, the method takes whatever on the screen buffer, so your approach is not ugly. Besides, it works, right? ;)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: take screenshot
« Reply #2 on: January 04, 2012, 11:00:27 am »
great, it takes screenshot, including your form on it. Besides hiding/showing my form in between,
which is ugly, I have no other idea how to take screenshot of everything behind my/focused form ?

Screenshot ignoring 1 form is pretty hard and gets broken aften by new OS releases. Up to Windows Vista there was an way to do this, but in Windows 7 already it stopped working. Aero broke it. In Linux one could try doing this with XComposite (I tried, is very hard) and in Mac maybe using the window listing way of doing screenshots.

Jishaxe

  • Full Member
  • ***
  • Posts: 103
  • Hobbist Programmer
Re: take screenshot
« Reply #3 on: March 16, 2012, 03:50:24 pm »
I wouldnt regard hiding the form as ugly! Taking the screenshot should only take a second anyway :)
Linux Mint 12
Windows 7 Home Premium
______________________
Definition of programmer: An organism that converts caffeine into software.

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: take screenshot
« Reply #4 on: March 16, 2012, 05:16:10 pm »
Yes, why not hide form ? Under kde you have KSnapshot app which does same thing - hides itself and then shows itself with loaded (stretched) screenshoot in small window, so then you can save it or do whatever.
Also, it have timeout so before it triggers, you have some time (eg. few seconds) to select desired form

Shebuka

  • Sr. Member
  • ****
  • Posts: 429
Re: take screenshot
« Reply #5 on: March 16, 2012, 06:56:29 pm »
I'm using Application.Hide for this purpose, but in some strange way it's not working well 100% of time, sometimes it simple not hide and i take screenshot with my forms...

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: take screenshot
« Reply #6 on: March 16, 2012, 10:30:02 pm »
Then fill an issue about it. Application.Hide should do exactly what it's name says 100% accurate on all platforms. What's problematic widgetset ?

Shebuka

  • Sr. Member
  • ****
  • Posts: 429
Re: take screenshot
« Reply #7 on: March 19, 2012, 10:11:24 am »
Then fill an issue about it. Application.Hide should do exactly what it's name says 100% accurate on all platforms. What's problematic widgetset ?
It's Carbon, i'v tried also to put a Application.ProcessMessages and then even a sleep(32)

Code: [Select]
var
  MyBitmap: TBitmap;
  ScreenDC: HDC;
  WrkJpg: TJpegImage;

...

      Application.Minimize;
      Application.ProcessMessages;

      Sleep(32);

      MyBitmap := TBitmap.Create;
      ScreenDC := GetDC(0);
      MyBitmap.LoadFromDevice(ScreenDC);

      Application.Restore;
      Application.BringToFront;

      //Per avere un elenco dei vari formati disponibili (png, bmp, xmp, ecc.):
      //http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Image_formats
      WrkJpg := TJpegImage.Create;
      try
        WrkJpg.CompressionQuality := 80;
        WrkJpg.Assign(MyBitmap);
        WrkJpg.SaveToFile(Utf8ToSys(ScreenName));
      finally
        FreeAndNil(WrkJpg);
      end;

      ReleaseDC(0, ScreenDC);
      FreeAndNil(MyBitmap);

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: take screenshot
« Reply #8 on: March 19, 2012, 07:33:43 pm »
What's so magic with sleep(32) ... it can be any number.... but anyway, as I said if Application.Minimize & Application.Restore does not work correct on some widgetset then please open an issue and attach compileable example ...

 

TinyPortal © 2005-2018