如何使用CGContext在OSX上绘制图像



我有一个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

最新更新