• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting CGImageRefs to NSImages, how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting CGImageRefs to NSImages, how?


  • Subject: Re: Converting CGImageRefs to NSImages, how?
  • From: "Sean McBride" <email@hidden>
  • Date: Tue, 26 Apr 2005 09:57:19 -0400
  • Organization: Rogue Research

On 2005-04-25 13:59, Andrew Platzer said:

>> 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];

Looks good, but it's not exactly what I'd call 'conversion' but more of a
'duplication'.  As I understand it, the CGImage and NSImage will not
share the same pixel memory, so depending on your uses this may be a big
problem. Actually, are the pixel values even guaranteed to be the same or
does the process of 'drawing' (ie CGContextDrawImage()) do some colour
conversion?  The docs say "Note that the appearance of the pixels in an
image that's drawn in a Quartz context can change due to factors such as:
    [...]
   -Color matching, if the image and context color spaces are different
	  -Color adjustments to match the display hardware"

And the OP, Ken, did seem to be worried about extracting the name of the
colour space.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


 _______________________________________________
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

  • Follow-Ups:
    • Re: Converting CGImageRefs to NSImages, how?
      • From: Scott Thompson <email@hidden>
    • Re: Converting CGImageRefs to NSImages, how?
      • From: Andrew Platzer <email@hidden>
References: 
 >Converting CGImageRefs to NSImages, how? (From: Ken Tozier <email@hidden>)
 >Re: Converting CGImageRefs to NSImages, how? (From: Andrew Platzer <email@hidden>)

  • Prev by Date: Re: How to get the CGDirectDisplayID?
  • Next by Date: Re: File Externsions Registration
  • Previous by thread: Re: Converting CGImageRefs to NSImages, how?
  • Next by thread: Re: Converting CGImageRefs to NSImages, how?
  • Index(es):
    • Date
    • Thread