CALayer renderInContext iOS7

Deadly 提交于 2019-12-22 17:39:05

问题


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.

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:


回答1:


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



来源:https://stackoverflow.com/questions/19024785/calayer-renderincontext-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!