Recent

Author Topic: Screenshot problem  (Read 2004 times)

simsee

  • Full Member
  • ***
  • Posts: 240
Screenshot problem
« on: September 09, 2020, 12:41:23 am »
Under Windows 10 when I use the snippet code from
https://wiki.freepascal.org/Developing_with_Graphics#Taking_a_screenshot_of_the_screen
I get the following runtime error: "Failed to get raw image from device".

How can the problem be overcome? Thanks so much.



jamie

  • Hero Member
  • *****
  • Posts: 7889
Re: Screenshot problem
« Reply #1 on: September 09, 2020, 03:36:48 am »
If you use the Print Screen button on your keyboard the screen will be copied into the clipboard.

From there you can use the TClipboard class to object it..

Also that snippet of code us using GetDC(1) instead of GetDC(0).. 

It really should be using GetDesktopWindow handle and from there you get the DC from that.

But all of in, I think you may find it harder these days to get a clean shot of the Windows 10 desktop.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7889
Re: Screenshot problem
« Reply #2 on: September 09, 2020, 03:41:51 am »
Code: Pascal  [Select][+][-]
  1.  B := TbitMap.Create;
  2.   B.LoadFromDevice(GetDC(GetDeskTopWindow));
  3.   Image1.Picture.Assign(B);
  4.   B.Free;                                      
  5.  

 I just ran that through a intercept of code I am currently working on..
The only true wisdom is knowing you know nothing

simsee

  • Full Member
  • ***
  • Posts: 240
Re: Screenshot problem
« Reply #3 on: September 09, 2020, 08:36:56 am »
Thanks Jamie. Your code works. The only problem is that it requires a function of Windows API, so it's not cross platform.

 

TinyPortal © 2005-2018