2012-05-22 53 views
1

我有一個CGContext,並試圖在上面繪製圖像。 我有一個NSImage *負載,我用其他方法。如何使用CGContext在OSX上繪製圖像

NSImage *check = [[NSImage alloc] initWithContentsOfFile:@"check.icns"]; 
CGContextDrawImage(arg2, CGRectMake(0, 0, 145, 15), check); 

但CGContext想要一個CGImage *我該如何使用我的NSImage *?

感謝

+0

[將NSImage *轉換爲CGImageRef?](http://stackoverflow.com/questions/2548059/turning-an-nsimage-into-a-cgimageref) – trojanfoe

回答

1

你應該考慮只打開它作爲一個CGImage在這種情況下,如果是你會需要它。如果NSImage你需要什麼,然後看-[NSImage CGImageForProposedRect:context:hints:]。此方法可能不需要副本,並且它可以產生理想的繪圖到目標上下文中的CGImage表示。

如果需要,您可以使用+[NSGraphicsContext graphicsContextWithGraphicsPort:flipped:]CGContext創建NSGraphicsContext