I have the following code:
我有以下代码:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(mainView.bounds.size, NO, [UIScreen mainScreen].scale);
}
else {
UIGraphicsBeginImageContext(mainView.bounds.size);
}
[mainView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
In mainView, there is a masked subview that does not appear in saveImage when using this method. However, I understand there used to be a UIGetScreenImage method pre iOS 4 that did capture such activity. My question is, what is the best way to capture CALayer activities in iOS 6? Is UIGetScreenImage still private?
在mainView中,有一个掩蔽子视图,在使用此方法时不会出现在saveImage中。但是,我知道以前有一个UIGetScreenImage方法pre - ios4,它确实捕获了这样的活动。我的问题是,在iOS 6中捕获CALayer的最佳方式是什么?UIGetScreenImage还是私人吗?
2 个解决方案
#1
2
I think there was a similar question about a week ago: Mask does not work when capturing a uiview to a uiimage
我想一个星期前也有一个类似的问题:在获取uiview到uiimage时,Mask不工作
On iOS6 there is a problem capturing a UIView with the mask applied (btw, in iOS 7 it has been fixed): you capture the image but the mask is not applied.
在iOS6上,有一个问题,用蒙版来捕捉UIView (btw,在ios7中已经修复了):你捕获了图像,但没有应用该掩码。
I posted a lengthy solution which involved applying the mask manually to the captured image. It's not very difficult and I also made a demo project of this. You can download it here:
我发布了一个冗长的解决方案,其中涉及到将掩码手工应用到捕获的图像。这并不难,我也做了一个演示项目。你可在此下载:
https://bitbucket.org/reydan/so_imagemask
https://bitbucket.org/reydan/so_imagemask
If I did not understand your problem correctly, please tell me so I can remove this answer.
如果我没有正确理解你的问题,请告诉我以便我可以删除这个答案。
#2
0
try getting the presentation layer instead, as it will contain the layer's state.
尝试获取表示层,因为它将包含层的状态。
[mainView.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html / / apple_ref / occ instm / CALayer / presentationLayer
#1
2
I think there was a similar question about a week ago: Mask does not work when capturing a uiview to a uiimage
我想一个星期前也有一个类似的问题:在获取uiview到uiimage时,Mask不工作
On iOS6 there is a problem capturing a UIView with the mask applied (btw, in iOS 7 it has been fixed): you capture the image but the mask is not applied.
在iOS6上,有一个问题,用蒙版来捕捉UIView (btw,在ios7中已经修复了):你捕获了图像,但没有应用该掩码。
I posted a lengthy solution which involved applying the mask manually to the captured image. It's not very difficult and I also made a demo project of this. You can download it here:
我发布了一个冗长的解决方案,其中涉及到将掩码手工应用到捕获的图像。这并不难,我也做了一个演示项目。你可在此下载:
https://bitbucket.org/reydan/so_imagemask
https://bitbucket.org/reydan/so_imagemask
If I did not understand your problem correctly, please tell me so I can remove this answer.
如果我没有正确理解你的问题,请告诉我以便我可以删除这个答案。
#2
0
try getting the presentation layer instead, as it will contain the layer's state.
尝试获取表示层,因为它将包含层的状态。
[mainView.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html / / apple_ref / occ instm / CALayer / presentationLayer