• 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 a CFImageRef to a NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting a CFImageRef to a NSImage


  • Subject: Re: Converting a CFImageRef to a NSImage
  • From: Randall Meadows <email@hidden>
  • Date: Thu, 5 Jun 2008 18:17:48 -0600

On Jun 5, 2008, at 6:15 PM, Nick Zitzmann wrote:

On Jun 5, 2008, at 6:12 PM, Felipe Monteiro de Carvalho wrote:

I would love to, but this method was added in 10.5

I am using 10.4

You can still do this in 10.4, just not with NSBitmapImageRep. Create an NSImage, call -lockFocus on it to create a CGContextRef, call [[NSGraphicsContext currentContext] graphicsPort] to get the context _after_ locking focus, draw the image, then call - unlockFocus. That ought to work.

Here's the method I wrote to do just that:

NSImage *CGImageRefToNSImage (CGImageRef cgImage)
{
   NSRect       imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
   CGContextRef imageContext = nil;
   NSImage      *newImage = nil;

// Get the image dimensions
imageRect.size = NSMakeSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage));


   // Create a new image to receive the Quartz image data
   newImage = [[NSImage alloc] initWithSize:imageRect.size];
   [newImage setCacheMode:NSImageCacheNever];
   [newImage lockFocus];

// Get the Quartz context and draw
imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextDrawImage(imageContext, *(CGRect *)&imageRect, cgImage);
[newImage unlockFocus];


   return([newImage autorelease]);
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Converting a CFImageRef to a NSImage (From: "Felipe Monteiro de Carvalho" <email@hidden>)
 >Re: Converting a CFImageRef to a NSImage (From: Nick Zitzmann <email@hidden>)
 >Re: Converting a CFImageRef to a NSImage (From: "Felipe Monteiro de Carvalho" <email@hidden>)
 >Re: Converting a CFImageRef to a NSImage (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Converting a CFImageRef to a NSImage
  • Next by Date: Re: gcc-4.0 Fail with Realease Configuration
  • Previous by thread: Re: Converting a CFImageRef to a NSImage
  • Next by thread: Re: Converting a CFImageRef to a NSImage
  • Index(es):
    • Date
    • Thread