下面是问题的截图和我正在使用的代码.
- (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];解决方法 您需要在渲染之前翻转目标上下文.
用这个更新你的代码,我刚解决了同样的问题:
CGAffinetransform flipVertical = CGAffinetransformMake(1,-1,pixelsHigh);CGContextConcatCTM(context,flipVertical);[[[self containerLayer] presentationLayer] renderInContext:context];总结
以上是内存溢出为你收集整理的cocoa – 使用带有geometryFlipped的CALayer的renderInContext:方法全部内容,希望文章能够帮你解决cocoa – 使用带有geometryFlipped的CALayer的renderInContext:方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)