Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting to/from NSImage, NSBitmapImageRep, CGContextRef, CGImageRef




On Feb 28, 2005, at 11:10 AM, Sean McBride wrote:

Hi!

I am new to this list (and Quartz) and I hope my question in on-topic.

Are there any convenience methods to convert between Cocoa and Quartz
images?  I've looked and have found that:
1) they don't seem to be 'toll free bridged'

NSImage "lives" at a much higher level than CGImage. NSImage implements a number of image cacheing schemes, can handle multiple representations of the same image, and much, much more. CGImage, in contrast, is a relatively simple class for handling sampled images. It really wouldn't make much sense for the two to be toll-free bridged. They "live in two different worlds".


2) WebKit provides NSImage to CGImageRef conversion
(WebConvertNSImageToCGImageRef())

In my specific case, I'm looking to convert an NSBitmapImageRep to a
'bitmap graphics context', and vice versa, though I'm curious about
conversions in general. (I know I could use CGBitmapContextCreate() and
-bitmapData, but I'm hoping for a one-liner :) )

I don't know of a one-liner. You say you want a "bitmap graphics context" which implies that you want to draw on the image. If that's the case then you could put the NSBitmapImageRep into an NSImage and use the lockFocus/unlockFocus mechanism to get a drawing context on the image.


If you want to create a CGBitmapImageContext on the same memory area as the NSBitmapImageRep, you could probably do that using CGBitmapContextCreate and the methods of NSBitmapImageRep. However, I couldn't recommend that because I suspect that the memory buffers of an NSImage, like the buffers of a CGImage, are probably supposed to be immutable outside of a lockFocus/unlockFocus type environment.

What exactly are you trying to do with the images?

Scott

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden
References: 
 >Converting to/from NSImage, NSBitmapImageRep, CGContextRef, CGImageRef (From: "Sean McBride" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.