1

I'm pretty sure that this topic has been discussed here several times, but I have a very weird issue related to conversion of a CGImage to a NSBitmapImageRep on OSX (10.8 and 10.9).

The CGImage object comes from AVAssetImageGenerator copyCGImageAtTime:actualTime:error: method. I currently found 2 ways to get what I want:

NSSize size = NSMakeSize(CGImageGetWidth(cGImage), CGImageGetHeight(cGImage));
NSImage *nsImage = [[NSImage alloc] initWithCGImage:cGImage size:size];

[nsImage lockFocus];
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, [nsImage size].width, [nsImage size].height)] autorelease];
[nsImage unlockFocus];
[nsImage release];

This properly works, but it is a somewhat slow. And I don't see the point of locking the graphic context when I only want to work with data...

I also tried the following:

bitmap = [[[NSBitmapImageRep alloc] initWithCGImage:cGImage] autorelease];

Which, hopefully, also works, but the blue color channel of the resulted image is missing.

So, how I can achieve this conversion without requiring to graphic locking, and without losing informations during the process?

0 Answers0