• 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: CoreData, image storage - NSImage or CGImage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData, image storage - NSImage or CGImage?


  • Subject: Re: CoreData, image storage - NSImage or CGImage?
  • From: Scott Thompson <email@hidden>
  • Date: Mon, 13 Aug 2007 17:12:20 -0500

On Aug 13, 2007, at 4:32 PM, Graham Perks wrote:

My app needs to store some image data in a Core Data binary field (I've de-normalized the image to a separate entity).

Right now it's all working storing NSImages... is this the right way to be doing it? Should I somehow be using CGImage or something else?

I do want to create a thumbnail of the images for performance, so I was looking at CGImageSourceCreateThumbnailAtIndex. Of course that doesn't use NSImage; the resulting thumbnail is a CGImage. I'd want to stash the thumbnail in Core Data so do I need to convert to an NSImage at that point? Or should I switch everything to store CGImages in CoreData?

It really doesn't matter. If you're comfortable with NSImage you can continue to use that. If not, then you could use CGImage.


If I was going to do it, I would just use CGImage for the whole thing, but that's because I know the CGImage path.

To do that, I would use a CGImageDestinationCreateWithData to create an image destination that is writing into a CFMutableDataObject. Since CFData is toll-free bridged to NSData I suspect I could use the Core Data destination directly. From there, you just add the image to the destination and finalize it.

However if you want to go the NSImage route, you could create an NSImage from the CGImage. This seems like a bit of overkill because you'd probably end up with an additional copy of the image data in memory. Still one technique to create an NSImage from a CGImage is to create the image, lock focus on it, then use. Another technique would be to create an NSImageRep that keeps track of a CGImageRef. Still another technique involves creating a CGBitmapContext, Drawing the image into that, then using NSBitmapImageRep to create a bitmap imageRep from the BitmapContext's data.

Any of these techniques will work.

Scott

_______________________________________________

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: 
 >CoreData, image storage - NSImage or CGImage? (From: Graham Perks <email@hidden>)

  • Prev by Date: Re: Expanding an NSMenuItem programmatically
  • Next by Date: Re: Screen Resolution
  • Previous by thread: Re: CoreData, image storage - NSImage or CGImage?
  • Next by thread: Screen Resolution
  • Index(es):
    • Date
    • Thread