我有一个CGContext,我试图在上面画一个图像。我有一个在其他方法上使用的 NSImage * 负载。
NSImage *check = [[NSImage alloc] initWithContentsOfFile:@"check.icns"];
CGContextDrawImage(arg2, CGRectMake(0, 0, 145, 15), check);
但是CGContext想要一个CGImage * 我如何使用我的NSImage * ?
谢谢
您应该考虑将其作为CGImage
打开,如果这就是您需要它的全部内容。如果您需要NSImage
,请参阅-[NSImage CGImageForProposedRect:context:hints:]
。此方法可能不需要副本,并且可以生成非常适合绘制到目标上下文中的CGImage
表示。
如果需要,您可以使用 +[NSGraphicsContext graphicsContextWithGraphicsPort:flipped:]
从CGContext
创建NSGraphicsContext
。