I've been wrestling with this all day and nothing is working. This code:

NSImage*              nsImage = [[NSImage alloc] initWithCGImage:cgImage 
size:NSZeroSize];
NSBitmapImageRep*     biRep = [[NSBitmapImageRep alloc] 
initWithCGImage:cgImage];
NSData*               nsImageData = [biRep 
TIFFRepresentationUsingCompression:NSTIFFCompressionPackBits factor:0];

Produces this error on the call to TIFFRepresentationUsingCompression:

CGImageDestinationFinalize failed for output type 'public.tiff'

I've also tried NSTIFFCompressionNone and NSTIFFCompressionLZW for the 
compression type.

Hmm, after working some more, I was able to get it to work be forcing the image 
rep to copy the pixels rather than simply glomming onto the CGImageRef:

NSImage*               nsImage = [[NSImage alloc] initWithCGImage:cgImage 
size:NSMakeSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage))];
NSBitmapImageRep*      bitmapImageRep;

[nsImage lockFocus];
bitmapImageRep = [[NSBitmapImageRep alloc] 
initWithFocusedViewRect:NSMakeRect(0, 0, nsImage.size.width, 
nsImage.size.height)];
[nsImage unlockFocus];

This gives me an image rep I can pass to CGImageDestinationAddImage to actually 
get the tiff data into the file. But I'm still curious why I can't get a 
CGImageRef, create an NSImage from it, and create a tiff from that.

--
Steve Mills
office: 952-818-3871
home: 952-401-6255



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to