CGImage to NSImage, or PDFPage?
CGImage to NSImage, or PDFPage?
- Subject: CGImage to NSImage, or PDFPage?
- From: Brian Postow <email@hidden>
- Date: Tue, 10 Aug 2010 17:45:45 -0400
I'm not sure if this is rightly a Cocoa question or Quartz, so I'm posting on both lists. Sorry for the double...
I have a CGImageRef, and I need to put it into a PDFPage. At the moment, the only way I see to do that is to turn it into an NSImage first. I've currently got:
NSImage* cgImageToNSImage(CGImageRef image)
{
int h, w;
h = CGImageGetHeight(image);
w = CGImageGetWidth(image);
NSMutableData* imgData = [NSMutableData dataWithLength: h * w * 4];
CGImageDestinationRef dest = CGImageDestinationCreateWithData
(imgData, kUTTypeTIFF, 1, NULL);
[imgData retain];
CGImageDestinationAddImage(dest, image, NULL);
CGImageDestinationFinalize(dest);
NSImage* img = [NSImage alloc];
[img initWithData: imgData];
CFRelease (dest);
[imgData release];
return img;
}
But this consistantly gives me the error: tiff data provider: Not a TIFF file, bad magic number 0 (0x0).
I'm pretty sure that the CGImage is a valid image, and I don't see any options to AddImage that look helpful...
Is there something obvious that I'm missing?
thanks.
Brian Postow
Senior Software Engineer
Acordex Imaging Systems
_______________________________________________
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