我需要在mac os项目中绘制一个图像。在iOS中,我可以使用UIGraphicsBeginImageContext
执行此操作
请举个例子,如何在mac os中绘制图像或模拟UIGraphicsBeginImageContext
api。
答案 0 :(得分:5)
如果你想要绘制一个NSImage,你会想要:
NSImage* anImage = [[NSImage alloc] initWithSize:NSMakeSize(100.0, 100.0)];
[anImage lockFocus];
// Do your drawing here...
[anImage unlockFocus];
来自Cocoa绘图documentation。