Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我可以打电话给CALayer';使用我创建的CGContextRef创建的renderInContext?_Ios_Calayer - Fatal编程技术网

Ios 我可以打电话给CALayer';使用我创建的CGContextRef创建的renderInContext?

Ios 我可以打电话给CALayer';使用我创建的CGContextRef创建的renderInContext?,ios,calayer,Ios,Calayer,如果我使用“UIGraphicsGetCurrentContext”与CALayer的RenderContext接口获得的上下文,我可以正确获得UIView的快照,但是如果我使用“CGBitmapContextCreate”创建的上下文,快照图像将镜像并旋转180度,即使两个上下文具有相同的“宽度”、“高度”、“位图信息”(8198,表示“kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little”)和“颜色空间”(等于CGColorSpace

如果我使用“UIGraphicsGetCurrentContext”与CALayer的RenderContext接口获得的上下文,我可以正确获得UIView的快照,但是如果我使用“CGBitmapContextCreate”创建的上下文,快照图像将镜像并旋转180度,即使两个上下文具有相同的“宽度”、“高度”、“位图信息”(8198,表示“kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little”)和“颜色空间”(等于CGColorSpaceCreateDeviceRGB()

代码正确运行:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.bounds.size.width, view.bounds.size.height), YES, 1);  
[view.layer renderInContext:UIGraphicsGetCurrentContext()];  
UIGraphicsEndImageContext();
代码将镜像并旋转图像:

CGContextRef context = 0;  
CGColorSpaceRef colorSpace;  
size_t width = view.bounds.size.width;  
size_t height = view.bounds.size.height;  
size_t bitsPerPixel = 32;  
size_t bitsPerComponent = 8;  
size_t bytesPerPixel = bitsPerPixel / bitsPerComponent;  
size_t bytesPerRow = width * bytesPerPixel;  
colorSpace = CGColorSpaceCreateDeviceRGB();  
uint32_t *buffer = new uint32_t[width * height];  
context = CGBitmapContextCreate(buffer,  
                                     width,  
                                     height,  
                                     bitsPerComponent,  
                                     bytesPerRow,  
                                     colorSpace,  
                                     kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little);  
CGColorSpaceRelease(colorSpace);  
[view.layer renderInContext:context]; 

有一篇帖子也谈到了同样的事情:答案是“在渲染之前翻转目标上下文”,但为什么?上下文有
ctm
属性,不是吗?我没有设置任何层的GeometryLipped属性,为什么要进行此转换?我读取了“view.layer”的GeometryLipped属性,它是“否”!读取。