Trying to get a TIFF from a CGImageRef isn't working
Trying to get a TIFF from a CGImageRef isn't working
- Subject: Trying to get a TIFF from a CGImageRef isn't working
- From: Steve Mills <email@hidden>
- Date: Wed, 15 Jan 2014 16:14:21 -0600
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 (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