データをフラットファイルとして保存containerLayerする前に、に変換しようとしている CALayer ( ) があります。プロパティが YES に設定されており、これが問題を引き起こしているようです。最終的に生成される PNG ファイルは、コンテンツを正しくレンダリングしますが、反転したジオメトリを考慮していないようです。左に表示されているコンテンツを正確に表すために、明らかに test.png を探しています。NSBitmapImageRepcontainerLayergeometryFlipped
以下に添付されているのは、問題のスクリーンショットと私が使用しているコードです。

- (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;
}
参考までに、生成されたファイルを実際に保存するコードを次に示しますNSBitmapImageRep。
NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:nil];
[imageData writeToFile:@"test.png" atomically:NO];