我正在尝试从屏幕捕获图像。可能使用像 NSRect 这样的输入参数来指定我想要屏幕的哪一部分。先感谢您。
最佳答案
您应该创建一个顶 View (NSScreenSaverWindowLevel
或更高版本)并保存其位图数据。这是示例代码(未测试):
[topView lockFocus];
NSImage *screenRectShot = [[NSImage alloc] initWithSize:NSMakeSize( screenRect.size.width, screenRect.size.height )];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:yourRect];
[screenRectShot addRepresentation:rep];
[rep release];
[topView unlockFocus];
关于objective-c - 如何从屏幕内容创建 NSImage 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6869793/