我正在mac OS X上写一个sreen cut APP,我只能这样看到窗口的可见部分:
CGImageRef imageRef = CGWindowListCreateImage(CGRectNull,
kCGWindowListOptionIncludingWindow,
self.windowID,
kCGWindowImageBoundsIgnoreFraming);
_windowImage = [[NSImage alloc] initWithCGImage:imageRef size:self.windowFrame.size];
CGImageRelease(imageRef);
但是当窗口可以滚动时,我想让整个部分不仅仅是可见部分,是否有人有一些建议? 谢谢!
答案 0 :(得分:0)
//capture 获取scrollview的截图
NSRect bounds = NSMakeRect(0, 0, [self.scrollView.documentView frame].size.width,[self.scrollView.documentView frame].size.height);
// //只能获取可见部分 only can grap the visible part of the scrollview
// NSBitmapImageRep* captureImage = [(NSView *)self.scrollView.documentView bitmapImageRepForCachingDisplayInRect:bounds];
// [self.scrollView cacheDisplayInRect:bounds toBitmapImageRep:captureImage];
// NSImage *image = [[NSImage alloc] initWithCGImage:[captureImage CGImage] size:captureImage.size];
//can grab the whole part
[self.scrollView lockFocus];
NSImage *image = [[NSImage alloc] initWithData:[(NSView *)self.scrollView.documentView
dataWithPDFInsideRect:bounds]];
[self.scrollView unlockFocus];