Taking Screenshots with Xojo

[quote=41723:@Michael Bzdega]Mike, your code sample works fine here but there is another question:

How can i capture the whole desktop instead of the app-window?[/quote]

For windows. Have a look at this link: https://forum.xojo.com/6009-sendkey-function Combined with this one: http://www.pctools.com/guides/scripting/detail/149/?act=reference

as for cocoa you can easily use “CGWindowListCreateImage” to capture entire screen and get a picture object
from a CGImage.

  const kCGWindowListOptionAll  = 0
  const kCGNullWindowID = 0
  const  kCGWindowImageDefault   = 0
  
  soft declare sub CGContextDrawImage lib "Carbon" (context as Ptr, rect as NSRect, image as Ptr)
  soft declare function CGWindowListCreateImage lib "Carbon" (r as CGRect, windowList as integer, winID as integer, winImageOptions as integer) as ptr
  dim s as CGRect = CGMakeRect(0,0,Screen(0).width, screen(0).height)
  dim p as ptr = CGWindowListCreateImage(s, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault)
  dim thePic as new Picture(s.w,s.h)
  CGContextDrawImage ptr(thepic.Graphics.Handle(Graphics.HandleTypeCGContextRef)),s, p

Well Rob, that’s not a screenshot. It’s a rendering of the windows you select.

I have those methods in my MBS Plugin, too:
https://www.monkeybreadsoftware.net/module-cgwindowmbs.shtml

The main use is for me things to render what’s behind a window or render each window on it’s own, so you can build a layered screen shot.

Christian,

You can for sure take screenshots with (desktop or a single window) if you know how to deal with the function (see constants & doc):
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CGWindow_Reference/Reference/Functions.html

Example:
https://www.dropbox.com/s/mxozh3ygeieicdu/screenshot.xojo_binary_project?dl=0

You can do that too. I’ve used it in my app to capture what’s behind. Sometime I have a suspicion that
you comment or post only to place your own plugins/ads.

if you look for real screenshot functions, you may better check CGDisplay functions.

A shell to ScreenCapture works very nicely in Mac OS X.

Might be on option but depends on the case.

I have been using it for a while, then I switched to ScreenRectMBS, which is cross platform and faster. But indeed, there are different solutions available.

[quote=41547:@Mike Cotrone]Michael this code from my method I have used. HTH also.

[code]
Dim pict As Picture
Dim d as new Date
// Create Timestamp for ScreenCapture Save Name
Dim timeStamp as string = str(d.Minute) + str(d.Second)
Dim f as FolderItem = GetSaveFolderItem(“image/png”,“ScreenCapture_” + timeStamp + “.png”)

If f <> Nil then
pict = New Picture(self.Width, self.Height, 32)
Self.DrawInto pict.Graphics, 0, 0
pict.Save(f, Picture.SaveAsPNG)
end if
[/code][/quote]

Dear Mr. Cotrone,

Will it work on Linux too ?

thanks
Regards,
Arief