Your best bet for creating a CGImage from an NSImage is probably to
create a CGBitmapContext on some memory that you own. That way you
can choose the color space and pixel format that makes the most
sense for the kind of image your working with. Then, with that
bitmap context you can create an NSGraphicsContext and draw the
NSImage. Once you've drawn the image you can use
CGBitmapContextCreateImage to create the CGImage.
Thanks. I put together some code using some sample code and some of my
own code (I haven't messed with CoreGraphics very much). But I'm still
having the same issues. When I first create the CGImage, everything
seems to work fine. I can get the height and width of it, push it's
contents back into an NSImage, and draw it. At creation time the
CGImageRef is working great. But when it comes time to draw the image
as part of view's display method, or something similar, the CGImage
seems to be corrupt. The height of the CGImageRef is returned to me as
0, the height is some unintelligible number, and it obviously draws as
just an empty space. This sounds like a memory related issue to me.
CGImageRefs created from a URL using CGImageSourceCreateWithURL work
just great and display correctly at display time, so I'm pretty sure
it's my code. I'm pasting my code below, so if someone could give it a
look over and make sure it's ok... I'll continue poking away at my
classes and make sure it's not an issue elsewhere.
As for why I'm in this situation... My app has some image management
stuff that is NSImage bound, so I'm frequently having to push
NSImage's into a document to be displayed in Core Animation. It would
be entirely possible to move my image management code to be CGImage
based, but given the amount of UI code attached to that part of the
program, I don't think it would be worth it. I was actually in this
situation before. When I was targeting Tiger I was using my own OpenGL
layering code, and I would have to create CIImage's from NSImage's.
For some reason NSImages -> CGImages is giving me more trouble though.
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden