1

I have a CGContext and I tried to draw an image on it. I have a NSImage * load that i used on other method .

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

But CGContext want a CGImage * how can I used my NSImage * ?

Thanks

kavaliero
  • 389
  • 1
  • 4
  • 22
  • possible duplicate of [Turning an NSImage* into a CGImageRef?](http://stackoverflow.com/questions/2548059/turning-an-nsimage-into-a-cgimageref) – trojanfoe May 22 '12 at 10:34

1 Answers1

1

You should consider just opening it as a CGImage in this case, if that is all you will need it for. If an NSImage is what you need, then see -[NSImage CGImageForProposedRect:context:hints:]. This method may not require a copy, and it can produce a CGImage representation ideal for drawing into the destination context.

If needed, you can create a NSGraphicsContext from a CGContext using +[NSGraphicsContext graphicsContextWithGraphicsPort:flipped:].

justin
  • 104,054
  • 14
  • 179
  • 226