gpt4 book ai didi

objective-c - 如何从屏幕内容创建 NSImage 实例

转载 作者:行者123 更新时间:2023-12-03 18:00:45 25 4
gpt4 key购买 nike

我正在尝试从屏幕捕获图像。可能使用像 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com