Grabbing what's behind a window

  • Dear Graphics Gurus:

    I'm trying to make a transparent "lens" effect on the screen using a
    core-image filter. When it's time to update, I orderOut the window
    I'm drawing in, grab the background, and then orderFront the window
    with the transformed contents. Unfortunately, this does not work - I
    keep grabbing the contents of my own window. I have tried the
    orderOut, then doing the grab in a performSelector:afterDelay, but
    this generates an annoying flicker.

    I'm wondering if what I'm trying to do is an impossibility - or is
    there some trick by which it can be done?

    Thanks!

    -Kenny
  • On Oct 29, 2007, at 3:49 PM, Kenny Leung wrote:

    > Dear Graphics Gurus:
    >
    > I'm trying to make a transparent "lens" effect on the screen using a
    > core-image filter. When it's time to update, I orderOut the window
    > I'm drawing in, grab the background, and then orderFront the window
    > with the transformed contents. Unfortunately, this does not work - I
    > keep grabbing the contents of my own window. I have tried the
    > orderOut, then doing the grab in a performSelector:afterDelay, but
    > this generates an annoying flicker.
    >
    > I'm wondering if what I'm trying to do is an impossibility - or is
    > there some trick by which it can be done?

    In Leopard, perhaps you could use CGWindowListCreateImage
    (CoreGraphics/CGWindow.h).

    -eric
  • On Oct 29, 2007, at 3:49 PM, Kenny Leung wrote:

    > I'm trying to make a transparent "lens" effect on the screen using a
    > core-image filter. When it's time to update, I orderOut the window
    > I'm drawing in, grab the background, and then orderFront the window
    > with the transformed contents. Unfortunately, this does not work - I
    > keep grabbing the contents of my own window. I have tried the
    > orderOut, then doing the grab in a performSelector:afterDelay, but
    > this generates an annoying flicker.
    >
    > I'm wondering if what I'm trying to do is an impossibility - or is
    > there some trick by which it can be done?

    If you can require Leopard, then your best bet would be to use the new
    CGWindow API. It will allow you to specifically exclude your
    application and capture the composited contents of the screen or any
    portion there of into a CGImageRef. Mike Paquette recently posted a
    summary of this (see his posts from 10/26) and a sample is in the
    pipeline to be released from DTS.
    --
    David Duncan
    Apple DTS Quartz and Printing
    <david.duncan...>
  • On Oct 29, 2007, at 3:49 PM, Kenny Leung wrote:

    > Dear Graphics Gurus:
    >
    > I'm trying to make a transparent "lens" effect on the screen using a
    > core-image filter. When it's time to update, I orderOut the window
    > I'm drawing in, grab the background, and then orderFront the window
    > with the transformed contents. Unfortunately, this does not work - I
    > keep grabbing the contents of my own window. I have tried the
    > orderOut, then doing the grab in a performSelector:afterDelay, but
    > this generates an annoying flicker.
    >
    > I'm wondering if what I'm trying to do is an impossibility - or is
    > there some trick by which it can be done?
    >
    > Thanks!
    >
    > -Kenny

    Starting in Mac OS X 10.5 On Mac OS X 10.5 you can read back
    information on other windows within the same GUI session as the
    calling process using the CGWindow API (defined in /System/Library/
    Frameworks/ApplicationServices.framework/Frameworks/
    CoreGraphics.framework/Headers/CGWindow.h).

    Images can be generated from a list of windows passed to
    CGWindowListCreateImageFromArray(),  or from a set of selection
    conditions ("All windows below this window") passed to
    CGWindowListCreateImage().  Various options control the bounds and
    content of the resulting image.

    In your case, you would want to grab an image for a specific rect for
    all windows below your window.  (The grab will stop as soon as it
    reaches an opaque window.)

    NSRect frame = [myWindow frame];
    CGWindowID wid = (CGWindowID)[myWindow windowNumber];

    CGImageRef image =  CGWindowListCreateImage( *(CGRect *)&frame,

    kCGWindowListOptionOnScreenBelowWindow, wid,
                                                  kCGWindowImageDefault );

    Refer to the comments in the header file for information on using
    these new APIs.

    Mike Paquette
    CoreGraphics Team
  • On Oct 29, 2007, at 4:15 PM, David Duncan wrote:

    > If you can require Leopard, then your best bet would be to use the
    > new CGWindow API. It will allow you to specifically exclude your
    > application and capture the composited contents of the screen or any
    > portion there of into a CGImageRef. Mike Paquette recently posted a
    > summary of this (see his posts from 10/26) and a sample is in the
    > pipeline to be released from DTS.

    And the sample now available. See Son of Grab at <http://developer/samplecode/SonOfGrab/index.html>
    --
    David Duncan
    Apple DTS Quartz and Printing
    <david.duncan...>
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today