I have a CALayer (containerLayer) that I'm looking to convert to a NSBitmapImageRep before saving the data out as a flat file. containerLayer has its geometryFlipped property set to YES, and this seems to be causing issues. The PNG file that is ultimately generated renders the content correctly, but doesn't seem to takes the flipped geometry into account. I'm obviously looking for test.png to accurately represent the content shown to the left.
For reference,here's a screenshot of the issue: http://i.stack.imgur.com/VasZH.png. You'll see containerLayer on the left and the generated .png file on the right. - (NSBitmapImageRep *)exportToImageRep { CGContextRef context = NULL; CGColorSpaceRef colorSpace; int bitmapByteCount; int bitmapBytesPerRow; int pixelsHigh = (int)[[self containerLayer] bounds].size.height; int pixelsWide = (int)[[self containerLayer] bounds].size.width; bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); context = CGBitmapContextCreate (NULL, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context == NULL) { NSLog(@"Failed to create context."); return nil; } CGColorSpaceRelease(colorSpace); [[[self containerLayer] presentationLayer] renderInContext:context]; CGImageRef img = CGBitmapContextCreateImage(context); NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:img]; CFRelease(img); return bitmap; } For reference, here's the code that actually saves out the generated NSBitmapImageRep: NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:nil]; [imageData writeToFile:@"test.png" atomically:NO]; _______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com