FROM : Andrew Platzer
DATE : Mon Apr 25 22:59:28 2005
On Apr 24, 2005, at 5:05 PM, Ken Tozier wrote:
> Sorry if this is an easy one but a thorough search of the list
> archives and the web didn't yield anything of much help.
>
> I'm trying to convert a CGImageRef returned from "[context
> createCGImage: img fromRect: imgRect]"
> to an NSImage so it can be used as the image in a drag operation
> but can't find any way to do the conversion.
Simple. Draw it using CG in a lock focus view. The NSGraphicsContext
has a 'graphicsPort' that gives you the CGContextRef. (The CGRect
coercion is to make the compiler happy even though CGRect has the
same struct layout as NSRect)
NSImage* image = [[NSImage alloc] initWithSize:rect.size];
[image lockFocus];
CGContextDrawImage([[NSGraphicsContext currentContext]
graphicsPort], *(CGRect*)&rect, imageRef);
[image unlockFocus];
Andrew Platzer
Application Frameworks
Apple Computer, Inc.
DATE : Mon Apr 25 22:59:28 2005
On Apr 24, 2005, at 5:05 PM, Ken Tozier wrote:
> Sorry if this is an easy one but a thorough search of the list
> archives and the web didn't yield anything of much help.
>
> I'm trying to convert a CGImageRef returned from "[context
> createCGImage: img fromRect: imgRect]"
> to an NSImage so it can be used as the image in a drag operation
> but can't find any way to do the conversion.
Simple. Draw it using CG in a lock focus view. The NSGraphicsContext
has a 'graphicsPort' that gives you the CGContextRef. (The CGRect
coercion is to make the compiler happy even though CGRect has the
same struct layout as NSRect)
NSImage* image = [[NSImage alloc] initWithSize:rect.size];
[image lockFocus];
CGContextDrawImage([[NSGraphicsContext currentContext]
graphicsPort], *(CGRect*)&rect, imageRef);
[image unlockFocus];
Andrew Platzer
Application Frameworks
Apple Computer, Inc.
| Related mails | Author | Date |
|---|---|---|
| Ken Tozier | Apr 25, 02:05 | |
| Ken Tozier | Apr 25, 07:35 | |
| Sean McBride | Apr 25, 20:25 | |
| Andrew Platzer | Apr 25, 22:59 | |
| Ken Tozier | Apr 26, 03:59 | |
| Sean McBride | Apr 26, 15:57 | |
| Andrew Platzer | Apr 27, 20:53 | |
| Scott Thompson | Apr 27, 21:16 |






Cocoa mail archive

