2
我需要一個來自Masked CALayer的UIImage。這是我使用的功能:來自MASKED CALayer的UIImage
- (UIImage *)imageFromLayer:(CALayer *)layer
{
UIGraphicsBeginImageContext([layer frame].size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
問題是不維護掩碼。 這是完整的代碼:
CAShapeLayer * layerRight= [CAShapeLayer layer];
layerRight.path = elasticoRight;
im2.layer.mask = layerRight;
CAShapeLayer * layerLeft= [CAShapeLayer layer];
layerLeft.path = elasticoLeft;
im3.layer.mask = layerLeft;
[viewImage.layer addSublayer:im2.layer];
[viewImage.layer addSublayer:im3.layer];
UIImage *image_result = [self imageFromLayer:viewImage.layer];
如果我想象的viewImage,結果是正確的,但如果我嘗試獲取相對於該層的圖像,面具丟失。
的可能重複[layer.renderInContext不layer.mask考慮?](http://stackoverflow.com/questions/4896296/layer-renderincontext-doesnt-take-layer-mask-into -帳戶) – 2013-04-08 10:51:58