Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>without getting any confirmations here, and not being able to use <code>cacheDisplayInRect</code> method; i've found that using <a href="http://file:///Developer/Documentation/DocSets/com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset/Contents/Resources/Documents/index.html#documentation/Carbon/Reference/CGWindow_Reference/Reference/Introduction.html" rel="nofollow">Quartz Window Services API</a> works.</p> <p>at seems that using <code>replaceSubView</code> needs a delay, so i did that with a block and was successful at capturing the bitmap.</p> <p>here's the code that works for me in case this helps someone else:</p> <pre><code>NSScrollView *sc = [self.browserView enclosingScrollView]; // i need the scrollView in the image NSRect viewRect = [sc visibleRect]; NSRect transRect = [[self.window contentView] convertRect:viewRect fromView:sc]; CGWindowID windowID = (CGWindowID)[self.window windowNumber]; CGWindowListOption singleWindowOptions = kCGWindowListOptionIncludingWindow; CGImageRef windowImage = CGWindowListCreateImage( CGRectNull, singleWindowOptions, windowID, kCGWindowImageBoundsIgnoreFraming); CGImageRef viewImage = CGImageCreateWithImageInRect(windowImage, NSRectToCGRect(transRect)); NSBitmapImageRep *bitMapRep = [[NSBitmapImageRep alloc] initWithCGImage:viewImage]; NSImage *image = [[NSImage alloc] init]; [image addRepresentation:bitMapRep]; NSImageView *iv = [[NSImageView alloc] initWithFrame:transRect]; [iv setImage: image]; double delayInSeconds = 0.01; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void) { [[self.window contentView] replaceSubview:sc with:iv]; }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload