Re: Converting CGImageRefs to NSImages, how?
Re: Converting CGImageRefs to NSImages, how?
- Subject: Re: Converting CGImageRefs to NSImages, how?
- From: Andrew Platzer <email@hidden>
- Date: Mon, 25 Apr 2005 13:59:28 -0700
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. |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden