我正在研究要对OpenGLView及其子视图进行快照的相机应用程序。下面的代码为我工作。升级到10.14.4(renderInContext)之后,当我拥有10.14.2时,功能停止了。
你能帮忙吗?
//captureImage is function which return Bitmap data which then convert to NSimage.
glView是我的OpenGLView,相机供稿在其中渲染
- (NSBitmapImageRep *)captureImage
{
NSImage *image = [[NSImage alloc] initWithSize:[glView bounds].size];
[image lockFocus];
CGContextRef ctx = [NSGraphicsContext currentContext].graphicsPort;
[glView.layer renderInContext:ctx];
[image unlockFocus];
NSData * tiffData = [image TIFFRepresentation];
NSBitmapImageRep * bitmap;
bitmap = [NSBitmapImageRep imageRepWithData:tiffData];
return bitmap;
}