Screen Capture

Share your advanced PureBasic knowledge/code with the community.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Also, to be able to publish high quality pictures, I don't want to scale up an original screen resolution screen grab....
Impossible! Images can only be scaled down 'without' image quality loss, not scaled up to higher resolutions. If an image is scaled up a 'blurring' occurs.
--Kale

Image
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Kale,

for that very reason I stated that I don't want to scale up. I'd like to see a solution that gives a much higher resolution bitmap, perhaps by re-rendering the selected window/control somewhere else in memory and then grab the image from that much larger presentation.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

for that very reason I stated that I don't want to scale up. I'd like to see a solution that gives a much higher resolution bitmap
So its pointless taking a screen grap then. You will have to draw whatever you need.
--Kale

Image
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

How do you highlight the roll overed region (with the mouse, so you can capture that active region only) and it must be highlighted to better see.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Einander,

thank you for pointing out this redundancy: a control is a window too... :)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

cecilcheah wrote:Hi there

Code: Select all

keybd_event_(#VK_SNAPSHOT,0,0,0) ; Snapshot of entire desktop.
looks like it does not work for win 95/98, it needs to be:

Code: Select all

keybd_event_(#VK_SNAPSHOT,1,0,0) ; Snapshot of entire desktop.
Anyone knows what about Win NT, Win 2000 or Win XP?

Cecil
Had to drag this up as I was looking for working screenshot code ... the above does not work because the snapshot thingie doesnt work some times :) For example, at the time of this post the print screen function works for all windows that do not have a dx screen on them. So I have to find some alternate means of taking a screenshot and PB code that doesnt require the scrnprnt function works perfectly :D

Anyways ...

The code provided here is missing the DEVMODE structure ... ... .. so they dont work.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

The code provided here is missing the DEVMODE structure ... ... .. so they dont work.
It should do, its defined in PB itself. press alt-s in the pb ide to see the predefined structures.
--Kale

Image
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Thanks for the info :) Just a tip for the rest :) If your taking a screenshot of just a window of yours, the following is required when taking the shot, or else the screenshot will cut off the window on the left and right. erk!

Notice, I am using winXP SP 2 on regular mode (no eye candy junk/theme).

Code: Select all

CaptureScreen(WindowX(),WindowY(),WindowWidth() + 5,WindowHeight() + 25)
Notice the + 5 and + 25 in the code.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

To take a screenshot of all of the screen I use this line :

Code: Select all

 ScreenCaptureAddress = CaptureScreen(0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN))
and it seems to take the whole desktop no matter the resolution (the easiest way I found to do so).

Thx to Kale for the code ;)
- Registered PB user -

Using PB 4.00
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Trying to figure out how to capture the screen every few seconds. I know there's Delay() and ElapsedMilliseconds() but I'm not sure if these are the correct commands to use for this? At least I haven't had any success with them (probably my lack of knowledge with setting a timer in PB). Any help would be great, thanks.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
Psychophanta
Addict
Addict
Posts: 4975
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Post by Psychophanta »

Baker,
use Delay() function into a loop. It should work.

Kale,
A bitmap handle is a memory address?
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

J. Baker wrote:Trying to figure out how to capture the screen every few seconds. I know there's Delay() and ElapsedMilliseconds() but I'm not sure if these are the correct commands to use for this? At least I haven't had any success with them (probably my lack of knowledge with setting a timer in PB). Any help would be great, thanks.
I would put all needed repeating code into a procedure then use:

Code: Select all

SetTimer_(WindowID(), #Timer, millisecs, @Procedure())
this then repeats the procedure at the millisec interval you specify. :)
--Kale

Image
User avatar
Psychophanta
Addict
Addict
Posts: 4975
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Post by Psychophanta »

Code: Select all

ScreenCaptureAddress = CaptureScreen(192, 112, 256, 256)
Kale,
here you assign as "Address" to a "bitmap handle".
If you know what the hell is exactly internally a handle (named by microsoft), please tell us, else forget this.
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
rotacak
User
User
Posts: 77
Joined: Tue Feb 14, 2006 2:00 pm

Re: Screen Capture

Post by rotacak »

This screengrabber is nice and works good. But only when you using it for capturing into clipboard. If you use the version from Kale, then there can be memory problem. Basically if you will remove that clipboard part then your memory is not released and still filling up. Not good when you want to repeatedly capture images.

I don't know why clipboard part can fix that.

Try this and look at your rising memory usage:

Code: Select all

Procedure CaptureScreen(Left, Top, Width, Height)
  dm.DEVMODE ;structure for CreateDC()
  srcDC = CreateDC_("DISPLAY", "", "", dm)
  trgDC = CreateCompatibleDC_(srcDC)
  BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height)
  SelectObject_( trgDC, BMPHandle)
  BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY)
  
  ;OpenClipboard_(#Null)
  ;EmptyClipboard_()
  ;SetClipboardData_(2, BMPHandle)
  ;CloseClipboard_()
  
  DeleteDC_( trgDC)
  ReleaseDC_( BMPHandle, srcDC)
  ProcedureReturn
EndProcedure

Repeat
  CaptureScreen( 0, 0, 800, 600)
  Delay(1)
ForEver
Uncomment the clipboard part and try again. No memory usage is rising anymore. Why?
User avatar
doctorized
Addict
Addict
Posts: 854
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Screen Capture

Post by doctorized »

In my case, "My computer" window is captured with some extra pixels. Why? See the image below. Win 10 Pro x64 fully updated
https://ibb.co/qdPggpj
Post Reply