开发者

capture hidden NSWindow

开发者 https://www.devze.com 2023-04-11 05:14 出处:网络
I\'m able to capture NSWindows which are 开发者_Go百科visible using code simular to the SonOfGrab Example

I'm able to capture NSWindows which are 开发者_Go百科visible using code simular to the SonOfGrab Example

But how can I capture a hidden NSWindow? Or what is the way to hide a NSWindow from the user but to still appear in de Windowserver?

Thanks in advance!


It isn't possible to capture the contents of an NSWindow which isn't visible on-screen. When a window is minimized/hidden/whatever, the visual representation is dropped to save memory.

(Not sure on exactly how this is managed, feel free to chime in if you have a deeper knowledge of the window system. I only know this from experience, trying to capture windows with CamTwist and BoinxTV.)


You can do it by:

NSImage *img = [[NSImage alloc] initWithCGImage:[window windowImageShot] size:window.frame.size];

category to NSWindow:

- (CGImageRef)windowImageShot
{
    CGWindowID windowID = (CGWindowID)[self windowNumber];
    CGWindowImageOption imageOptions = kCGWindowImageBoundsIgnoreFraming | kCGWindowImageNominalResolution;
    CGWindowListOption singleWindowListOptions = kCGWindowListOptionIncludingWindow;
    CGRect imageBounds = CGRectNull;

    CGImageRef windowImage = CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions);

    return windowImage;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消