简体   繁体   English

CALayer renderInContext iOS7

[英]CALayer renderInContext iOS7

I'm rendering multiple layers to get one final image. 我正在渲染多个图层以获得一张最终图像。 One of the images contains a face, and another one contains a background with a transparent gradient around the face so that the real background is hidden. 其中一幅图像包含一张脸,另一幅图像包含一张在脸部周围具有透明渐变的背景,从而隐藏了真实的背景。 In iOS6 it works perfectly but it is creating a weird effect with the transparent gradient in iOS7. 在iOS6中,它可以完美工作,但在iOS7中,它的透明渐变会产生怪异的效果。

The code: 编码:

CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[faceImageView.layer renderInContext:context];
[fakeBackgroundImageView.layer renderInContext:context];

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

The results in iOS6 and iOS7: iOS6和iOS7中的结果:

iOS6的

IOS 7

Ok, the solution was changing this line: 好的,解决方案正在更改此行:

UIGraphicsBeginImageContext(rect.size);

for this one: 为此:

UIGraphicsBeginImageContextWithOptions(rect.size, TRUE, [[UIScreen mainScreen] scale]);

Now it also works in iOS7 现在它也可以在iOS7中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM