title: How to grab an image of an offscreen NSWindow?
body: <p>I'm trying to get an image of an offscreen window to use in a <code>CALayer</code>-based animation, but no matter which method I try I cannot get an image out the other side. Here is the code I've been using on a custom <code>NSWindow</code> subclass in my project:</p>
  
  <pre><code>CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, 
                                                   kCGWindowListOptionAll, 
                                                   (CGWindowID)[self windowNumber], 
                                                   kCGWindowImageDefault);
  </code></pre>
  
  <p>This is what the image should look like:</p>
  
  <p><img src="https://i.stack.imgur.com/WBCKO.png" alt="alt text"></p>
  
  <p>and here's what I get (ignore the slightly larger size - that's my fault in the rendering of the image):</p>
  
  <p><img src="https://i.stack.imgur.com/CoNEW.png" alt="alt text"></p>
  
  <p>Can anyone see where I'm going wrong? Strangely, Quartz Debug can see the window image without issue, but the <a href="http://developer.apple.com/library/mac/#samplecode/SonOfGrab/Introduction/Intro.html" rel="nofollow noreferrer">Son of Grab sample code from Apple</a> cannot.</p>